Configuration

Damien Lecan edited this page Oct 7, 2015 · 39 revisions

In the next descriptions, APP_HOME is the root of your Play2 application you want to package as a WAR file.

Add Play2War plugin

Play2War is compatible with all Play2 versions, but Play 2.1 APIs are incompatibles with thoses from Play 2.0. So you have to choose the right version of Play2War:

Supported versions

  • Play 2.2.x : P2W 1.2.1
  • Play 2.3.0 -> 2.3.1 : P2W 1.3-beta1 (Scala 2.10 & 2.11)
  • Play 2.3.2+ : 1.3-beta3 (Scala 2.10 & 2.11)
  • Play 2.4.0+ : 1.4-beta1 (Scala 2.10 & 2.11)

Archived versions

  • Play 2.0.x : P2W 0.8.1 and earlier
  • Play 2.1.0 -> 2.1.3 : P2W 1.0.2
  • Play 2.1.4+ : P2W 1.1.1

Repository configuration

Play 2.4 and more

Add in APP_HOME/project/plugins.sbt:

addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "<Play2War_version>")

Play 2.1, Play 2.2 and Play 2.3

Add in APP_HOME/project/plugins.sbt:

resolvers += Resolver.url(
  "bintray-sbt-plugin-releases",
   url("http://dl.bintray.com/content/sbt/sbt-plugin-releases"))(
       Resolver.ivyStylePatterns)

addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "<Play2War_version>")

Play 2.0

Add in APP_HOME/project/plugins.sbt:

resolvers += "Play2war plugins release" at "http://repository-play-war.forge.cloudbees.com/release/"

addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "0.8.1")

Import Play2War SBT settings

Depending on your configuration, the build file can be either APP_HOME/project/Build.scala or APP_HOME/build.sbt. Change the one that already exists like this:

In APP_HOME/project/Build.scala, add:

...
import ... // other imports
import com.github.play2war.plugin._
...

In APP_HOME/build.sbt, add:

...
import ... // other imports
import com.github.play2war.plugin._
...

Add all Play2war settings in your project configuration

In APP_HOME/project/Build.scala:

add .settings(Play2WarPlugin.play2WarSettings: _*) like this:

val appVersion      = "1.0-SNAPSHOT"
...
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA)
  .settings(Play2WarPlugin.play2WarSettings: _*)
  .settings(
    // ... Your own settings here
)

In APP_HOME/build.sbt:

add Play2WarPlugin.play2WarSettings

...
version := "1.0-SNAPSHOT"
<blank line>
Play2WarPlugin.play2WarSettings
<blank line>
// ... Your own settings here

Play2War settings must be inserted before your own settings.

## Configure servlet container version

You have to choose on which kind of servlet container your Play2 application will be deployed:

  • Servlet 3.1: Tomcat 8, Wildfly 8, Glassfish 4, Jetty 9, ...
  • Servlet 3.0: Tomcat 7, JBoss 7, JBoss EAP 6, Glassfish 3, Jetty 8, ...
  • Servlet 2.5: Tomcat 6, JBoss AS 5/6, JBoss EAP 5, Glassfish 2, Jetty 7, ...

If you get some 404 errors, you have probably choosen the wrong servlet container version.

Servlet 3.1 container configuration

In APP_HOME/project/Build.scala:

val appVersion      = "1.0-SNAPSHOT"
...
val main = play.Project(appName, appVersion, appDependencies)
  .settings(Play2WarPlugin.play2WarSettings: _*)
  .settings(
    // ... Your own settings here
    Play2WarKeys.servletVersion := "3.1"
)

In APP_HOME/build.sbt:

version := "1.0-SNAPSHOT"
...
Play2WarPlugin.play2WarSettings

Play2WarKeys.servletVersion := "3.1"

Don't look for any web.xml file in the generated WAR, Play2War uses annotation-driven servlet to be loaded.

Servlet 3.0 container configuration

In APP_HOME/project/Build.scala:

val appVersion      = "1.0-SNAPSHOT"
...
val main = play.Project(appName, appVersion, appDependencies)
  .settings(Play2WarPlugin.play2WarSettings: _*)
  .settings(
    // ... Your own settings here
    Play2WarKeys.servletVersion := "3.0"
)

In APP_HOME/build.sbt:

version := "1.0-SNAPSHOT"
...
Play2WarPlugin.play2WarSettings

Play2WarKeys.servletVersion := "3.0"

Don't look for any web.xml file in the generated WAR, Play2War uses annotation-driven servlet to be loaded.

Servlet 2.5 container configuration

In APP_HOME/project/Build.scala:

val appVersion      = "1.0-SNAPSHOT"
...
val main = play.Project(appName, appVersion, appDependencies)
  .settings(Play2WarPlugin.play2WarSettings: _*)
  .settings(
    // ... Your own settings here
    Play2WarKeys.servletVersion := "2.5"
)

In APP_HOME/build.sbt:

version := "1.0-SNAPSHOT"
...
Play2WarPlugin.play2WarSettings

Play2WarKeys.servletVersion := "2.5"

Play2War will generate a default war/WEB-INF/web.xml file for you if necessary (= doesn't exist). You can commit it in your SCM or modify it if needed (new filters, encoding, ...). This war/WEB-INF/web.xml will be then embedded in the generated WAR.

Other build parameters

Several other build parameters can be customized to fit your needs.

Configure logging

If you plan to use JBoss7, please read JBoss7 logging configuration instead.

You probably need to override default Play2 logging configuration because:

  • An external file will be written in $USER_HOME/logs/...

  • STDOUT appender pattern can be improved

Create a file APP_HOME/conf/logger.xml with the following content :

<configuration>
    
  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
    </encoder>
  </appender>
  
  <logger name="play" level="INFO" />
  <logger name="application" level="INFO" />
  
  <!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
  <logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
  <logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
  <logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />

  <root level="ERROR">
    <appender-ref ref="STDOUT" />
  </root>
  
</configuration>

Embed custom WAR configuration files

You can embed custom WAR configuration files, such as MANIFEST.MF, web.xml, ... For this, copy them in your APP_HOME/war folder. Don't forget to add subfolders !

Samples:

  • APP_HOME/war/myfile.txt will result in myapp.war!/myfile
  • APP_HOME/war/META-INF/MANIFEST.MF will result in myapp.war!/META-INF/MANIFEST.MF
  • APP_HOME/war/WEB-INF/web.xml will result in myapp.war!/WEB-INF/web.xml

Special configurations

Runtime parameters

Several runtime parameters can be customized to fit your needs.

Next step

Continue with Usage.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.