从Play Framework生成战争

时间:2013-11-12 17:11:08

标签: playframework

是否有可用于从Play框架项目生成战争的插件?

c:\>myproject>play war

上面提到的命令可以生成战争,但是当部署在Weblogic或Websphere上时,它不会被部署。 过去曾尝试过,但未能成功部署。

3 个答案:

答案 0 :(得分:1)

如果您的项目基于play framework 2.x,这个插件过去对我有用: https://github.com/dlecan/play2-war-plugin

已成功将其与Play 2.1.1版一起使用。

答案 1 :(得分:1)

简称:https://github.com/dlecan/play2-war-plugin

创建并部署为WAR

修改了两个文件以实现相同的工作/将Play应用程序部署为WAR。

1) under "/playframeworkProject/project/plugins.sbt" add the following at the bottom

    // Added for WAR deployment support
    addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.2-beta1")

2) under "/playframeworkProject/project/Build.scala"

    import com.github.play2war.plugin._

Make following code changes.

    object ApplicationBuild extends Build {
    .
    .
    .

    lazy val main = play.Project(appName, appVersion, appDependencies)
     .settings(Play2WarPlugin.play2WarSettings: _*)
    .
    .
    resourceDirectory in IntegrationTest <<= baseDirectory /"it/resources",
      Play2WarKeys.servletVersion := "3.0")
    .
    .
    }

最终应该看起来像&gt;&gt;&gt;

object ApplicationBuild extends Build {

  import com.mckesson.builder.Resolvers._
  val appName         = "YourPlayProjectName"
  val appVersion      = "1.0-SNAPSHOT" 


   val appDependencies = com.companyname.builder.Dependencies.YourPlayProjectName

   resolvers :=  com.companyname.builder.Resolvers.XYZResolvers

    lazy val main = play.Project(appName, appVersion, appDependencies)
     .settings(Play2WarPlugin.play2WarSettings: _*)
     .settings(  playCommonSettings: _*
                ).configs( IntegrationTest ).settings( Defaults.itSettings :_*)
         .settings(scalaSource in IntegrationTest <<=  baseDirectory /"it" ,
          scalaSource in Test <<= baseDirectory /"test",
          resourceDirectory in IntegrationTest <<= baseDirectory /"it/resources",
      Play2WarKeys.servletVersion := "3.0")



}

将YourPlayProjectName转换为WAR

通过sbt clean publish-local重新构建项目 cd到YourPlayProjectName目录 运行play war或sbt war来生成WAR

将应用程序部署为WAR到Tomcat

转到YourPlayProjectName / target /查找WAR

将WAR重命名为ROOT.war

将其复制到Tomcat 7的webapps文件夹

请注意,您需要定义CATALINA_HOME环境变量并将其/ bin添加到Path

示例:C:&gt; echo%CATALINA_HOME%C:\ apache \ apache-tomcat-7.0.40      4.启动数据库

 5. Start Tomcat 7 with this command from your command prompt (no specific location as long as your CATILANA_HOME is set correctly in your environment variable) catalina start

 6. Start your other dependencies if any to make sure your application works.

在浏览器中,点击http://:8080以查看您的应用程序是否正常运行和部署。

享受!!

答案 2 :(得分:1)

此页面一定会帮助您了解生成war文件所需的配置... https://github.com/play2war/play2-war-plugin/wiki/Configuration

通常,您必须在添加配置的位置进行更改:
1. plugins.sbt(project-root/project/)
2. build.sbt (project-root)

播放2.4及以上

  1. plugins.sbt
  2. addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.4-beta1")

    1. build.sbt

      import com.github.play2war.plugin._
      
      libraryDependencies ++= Seq(
        "com.github.play2war" % "play2-war_2.9.1" % "0.8.2"   # Change version
      )
      
       Play2WarPlugin.play2WarSettings
      
       Play2WarKeys.servletVersion := "2.5" # Change as per your requirement(3.0 or 3.1 etc)
      

      addSbtPlugin(“com.github.play2war”%“play2-war-plugin”%“1.4-beta1”)

    2. 运行[sbt war]