首先,使用过play1.*版本的开发者应该都知道要将play项目打包发布,可以直接使用play war命令,但是到了2.*以上的版本,已不再支持play war来打包项目。这里将原因解释如下:
They haven't done this because the Servlet3.1spec has not been released yet. Play 2 supports some features that cannot be supported with Servlet containers <3.1 (probably stuff like web sockets). However, there is a 3rd party plugin that provides this functionality (as long as you avoid the unsupported features):https://github.com/dlecan/play2-war-plugin
所以,想了解原文的,请直接去上述官网细致了解
下面,我简单介绍如下:
1.plugins.sbt
logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
addSbtPlugin("play" % "sbt-plugin" % "2.0.4")
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "0.8.1")
2.Build.scala
import com.github.play2war.plugin._
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
Play2WarKeys.servletVersion := "2.5" //servlet容器版本
).settings(Play2WarPlugin.play2WarSettings: _*)
3.root context deployment
Tomcat 7, Jetty 7/8/9
Rename the generated war ROOT.war
before deployment.
4.启动服务器,查看