首先,使用過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.啓動服務器,查看