play 打包成war

play framework 2.0 暂时不支持打包成war 。对于要部署到tomcat 还是有一定麻烦的,但是在git上还是有支持打包的方法。

github.com/dlecan/play2-war-plugin  本文参考了使用指南进行了一次部署.

  • 添加play2war插件

Play2War是兼容所有PLAY2版本的,但play 2.1的API与play 2.0 系统不相容。所以,你必须选择合适的版本Play2War,下面列出判断标准:

  1. Play 2.0.x => Play2War 0.8.1 and earlier
  2. Play 2.1.x => Play2War 0.9.x and later

对比自己的版本,在APP_HOME/project/plugins.sbt 下面添加如下代码:

For Play 2.1.x applications:

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

For Play 2.0.x applications:

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

addSbtPlugin(“com.github.play2war” % “play2-war-plugin” % “0.8.1″)

  • 导入Play2War SBT设置

在你的 APP_HOME/project/Build.scala 文件的上面添加如下代码,注意书写正确

...
import ... // other imports
import com.github.play2war.plugin._ 
...
  • 在你的项目配置里添加play2war的设置
val appVersion      = "1.0-SNAPSHOT"
...
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA)
  .settings(Play2WarPlugin.play2WarSettings: _*)
  .settings(
    // ... Your own settings here
)
  • 配置Servlet容器版本

选择哪种servlet容器PLAY2的将应用程序部署:

  1. Servlet 3.0: Tomcat 7, JBoss 7, JBoss EAP 6, Glassfish 3, Jetty 8, …
  2. Servlet 2.5: Tomcat 6, JBoss AS 5/6, JBoss EAP 5, Glassfish 2, Jetty 7, …

Servlet 3.0的容器配置:

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

Servlet 2.5的容器配置:

val appVersion      = "1.0-SNAPSHOT"
...
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA)
  .settings(Play2WarPlugin.play2WarSettings: _*)
  .settings(
    // ... Your own settings here
    Play2WarKeys.servletVersion := "2.5"
)
  • 运行play war 命令生成war包

所有配置完毕后,在app的根目录后面,输入

play war

完毕后,就可以在项目的target目录下,发现生成的war包了

你可能感兴趣的:(play 打包成war)