Skip to main content

How to mavenify a Play 2 application

This article is for developers who want to develop web-apps with Play 2 Framework but are required to integrate these new web-apps in an existing build process based on Maven.

Lucky you, someone already started a project to do this: play2-maven-plugin.
Unfortunately, this Maven plugin does not support hot reloading yet, which makes the development process painful.

To make it short, you still need SBT to enjoy Play 2 hot reloading feature... but you do not want to have to maintain both Maven and SBT configurations.
The trick is to configure SBT from Maven pom files with sbt-pom-reader.

This is how you need to configure your play2-maven project:
<my-maven-project>/
  pom.xml                  <- Your maven build
  build.sbt                <- the sbt Play 2 configuration
  project/
     build.properties      <- the sbt version specification
     build.scala           <- the sbt build definition
     plugins.sbt           <- the sbt plugin configuration

  ..                       <- Whatever files are normally in your maven project.

Each of the files should have the following contents.
pom.xml: @see play2-maven-plugin usage

build.sbt:
play.Project.playJavaSettings //or play.Project.playScalaSettings

project/build.properties:
sbt.version=0.13.0

project/build.scala:
object BuildFromMavenPomSettings extends com.typesafe.sbt.pom.PomBuild

project/plugins.sbt:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-pom-reader" % "1.0.1")


Now you can use Maven to build your Play 2 application and SBT to develop it with hot reloading. 

Happy coding!

Source: https://github.com/sbt/sbt/issues/1123

Comments

Popular posts from this blog

IntelliJ IDEA not starting: Initial heap size set to a larger value than the maximum heap size

IntelliJ IDEA didn't want to start this morning. Got the following error when trying to start it from a shell: Error occurred during initialization of VM Initial heap size set to a larger value than the maximum heap size What happened is that IntelliJ IDEA loaded the JVM Options from the new custom vmoptions file in the config directory. On Windows: %APPDATA%\Roaming\JetBrains\IntelliJIdea2020.1\idea64.exe.vmoptions On macOs: ~/Library/Application Support/JetBrains/IntelliJIdea2020.1/idea.vmoptions This file was not updated properly when I updated IntellIJ IDEA. It contained: -Xms4g -Xmx2048m Fixed the issue by editing this file: -Xms4g -Xmx4g Source: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004701620-idea-vmoptions-not-used-by-default  

Accessing a Docker container running in a Docker-Machine on localhost

On Linux you can access your running Docker container on localhost or remotely by publishing the desired port. On macOS it will only give you access to the Docker container from the Docker-Machine it is running on, i.e. from docker-machine ip <machine_name> . To access it on localhost, you can use ssh port forwarding: docker-machine ssh <machine_name> -fNTL <local_port> :localhost:<machine_port> You can now access your Docker container on localhost:<local_port> . Bonus: Accessing your Docker container from a remote computer. By default, with ssh -L , the local port is bound for local use only. You can use the bind _address option to make your Docker container available publicly: docker-machine ssh <machine_name> -fNTL \*:<local_port>:<localhost>:<machine_port> You can now access your Docker container on <your_ip>:<local_port> .