Play Framework 2.3.7:静态资产位置不在生产中

时间:2014-12-07 10:25:03

标签: java scala playframework requirejs playframework-2.3

我已经看到了一些关于此的问题,但似乎无法深究它。

我有一个Play Framework 2.3.7(Activator 1.2.12)网站,当我在开发模式下运行时,一切正常。当我在生产模式下启动时,我收到以下错误:

 [app] $ start
 [info] Wrote C:\Users\App\git\website2.0\target\scala-2.10\app_2.10-1.0-
 SNAPSHOT.pom
 [info] Main Scala API documentation to C:\Users\App\git\website2.0\target\scala-
 2.10\api...
 [info] Compiling 57 Scala sources and 58 Java sources to C:\Users\App\git\websit
 e2.0\target\scala-2.10\classes...
 [error] C:\Users\App\git\website2.0\target\scala-2.10\twirl\main\views\html\admi
 n\shared\foot.template.scala:29: value at is not a member of controllers.Reverse
 Assets
 [error] Seq[Any](forApp.raw/*1.1*/("""<script data-main=""""),_display_(/*1.21*/
 routes/*1.27*/.Assets.at("javascript/admin.js")),forApp.raw/*1.60*/("""" type="t
 ext/javascript" src=""""),_display_(/*1.91*/routes/*1.97*/.Assets.at("lib/requir
 ejs/require.js")),forApp.raw/*1.135*/(""""></script>
 [error]
                       ^
 [error] C:\Users\App\git\website2.0\target\scala-2.10\twirl\main\views\html\admi
 n\shared\head.template.scala:31: value at is not a member of controllers.Reverse
 Assets
 [error] <link rel="stylesheet" media="screen" href=""""),_display_(/*3.46*/route
 s/*3.52*/.Assets.at("stylesheets/admin.css")),forApp.raw/*3.87*/("""">
 [error]
                  ^
 [error] C:\Users\App\git\website2.0\app\views\admin\shared\foot.scala.html:1: va
 lue at is not a member of controllers.ReverseAssets
 [error] <script data-main="@routes.Assets.at("javascript/admin.js")" type="text/
 javascript" src="@routes.Assets.at("lib/requirejs/require.js")"></script>
 [error]                                   ^
 [error] C:\Users\App\git\website2.0\app\views\admin\shared\head.scala.html:3: va
 lue at is not a member of controllers.ReverseAssets
 [error] <link rel="stylesheet" media="screen" href="@routes.Assets.at("styleshee
 ts/admin.css")">
 [error]                                                              ^
 [error] C:\Users\App\git\website2.0\target\scala-2.10\twirl\main\views\html\home
 .template.scala:38: value at is not a member of controllers.ReverseAssets
 [error]                 <div class="item active" style="background-image:url("""
 ),_display_(/*10.71*/routes/*10.77*/.Assets.at("images/bg-app-list.jpg")),fo
 rApp.raw/*10.117*/(""")">
 [error]
                                             ^
 [error] C:\Users\App\git\website2.0\app\views\home.scala.html:10: value at is no
 t a member of controllers.ReverseAssets
 [error]                 <div class="item active" style="background-image:url(@ro
 utes.Assets.at("images/bg-app-list.jpg"))">
 [error]
                      ^
 [error] C:\Users\App\git\website2.0\target\scala-2.10\twirl\main\views\html\shar
 ed\foot.template.scala:29: value at is not a member of controllers.ReverseAssets

 [error] Seq[Any](forApp.raw/*1.1*/("""<script data-main=""""),_display_(/*1.21*/
 routes/*1.27*/.Assets.at("javascript/main.js")),forApp.raw/*1.59*/("""" type="te
 xt/javascript" src=""""),_display_(/*1.90*/routes/*1.96*/.Assets.at("lib/require
 js/require.js")),forApp.raw/*1.134*/(""""></script>
 [error]
                  ^
 [error] C:\Users\App\git\website2.0\target\scala-2.10\twirl\main\views\html\shar
 ed\head.template.scala:31: value at is not a member of controllers.ReverseAssets

 [error] <link rel="stylesheet" media="screen" href=""""),_display_(/*3.46*/route
 s/*3.52*/.Assets.at("stylesheets/main.css")),forApp.raw/*3.86*/("""">
 [error]
                  ^
 [error] C:\Users\App\git\website2.0\app\views\shared\foot.scala.html:1: value at
  is not a member of controllers.ReverseAssets
 [error] <script data-main="@routes.Assets.at("javascript/main.js")" type="text/j
 avascript" src="@routes.Assets.at("lib/requirejs/require.js")"></script>
 [error] C:\Users\App\git\website2.0\target\scala-2.10\twirl\main\views\html\shar
 ed\nav.template.scala:39: value at is not a member of controllers.ReverseAssets
 [error]                                   ^
 [error]                 <img src=""""),_display_(/*11.28*/routes/*11.34*/.Assets
 .at("images/logo/small_beta.png")),forApp.raw/*11.74*/("""">
 [error]
  ^
 [error] C:\Users\App\git\website2.0\app\views\shared\head.scala.html:3: value at
  is not a member of controllers.ReverseAssets
 [error] <link rel="stylesheet" media="screen" href="@routes.Assets.at("styleshee
 ts/main.css")">
 [error]                                                              ^
 [error] C:\Users\App\git\website2.0\app\views\shared\nav.scala.html:11: value at
  is not a member of controllers.ReverseAssets
 [error]                 <img src="@routes.Assets.at("images/logo/small_beta.png"
 )">
 [error]                                                    ^
 [info] Packaging C:\Users\App\git\website2.0\target\App-1.0-SNAPSHOT-ass
 ets.jar ...
 [info] No documentation generated with unsucessful compiler run
 [error] 6 errors found
 [error] 6 errors found
 [info] Done packaging.
 [error] (compile:doc) Scaladoc generation failed
 [error] (compile:compile) Compilation failed

 Cannot start with errors.

问题似乎是围绕requirejs及其资产路径。第一个页脚错误的代码如下:

 <script data-main="@routes.Assets.at("javascript/admin.js")" type="text/javascript"      src="@routes.Assets.at("lib/requirejs/require.js")"></script>

我的资产路线档案是:

# Map static resources from the /public folder to the /assets URL path
GET         /assets/javascript/routes.js                  controllers.Application.javascriptRoutes()
GET         /assets/javascript/admin_routes.js            controllers.admin.Application.javascriptRoutes()
GET         /assets/*file                                 controllers.Assets.at(path="/public", file)

这是我的build.sbt

import WebKeys._
import RjsKeys._
import play.PlayJava

name := """app"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava, SbtWeb)

libraryDependencies ++= Seq(
  javaJpa,
  javaJdbc,
  cache,
  "org.hibernate" % "hibernate-core" % "4.2.3.Final",
  "org.hibernate" % "hibernate-entitymanager" % "4.2.3.Final",
  "mysql" % "mysql-connector-java" % "5.1.31",
  "org.webjars"   %% "webjars-play"  % "2.2.0",
  "joda-time" % "joda-time-hibernate" % "1.3",
  "org.mindrot" % "jbcrypt" % "0.3m",
  "net.sf.flexjson" % "flexjson" % "3.2",
  "org.apache.commons" % "commons-lang3" % "3.3.2",
  "com.clever-age" % "play2-elasticsearch" % "1.1.0",
  // WebJars (i.e. client-side) dependencies
  "org.webjars" % "requirejs" % "2.1.14-1",
  "org.webjars" % "jquery" % "1.11.1",
  "org.webjars" % "bootstrap" % "3.1.1-2" exclude("org.webjars", "jquery"),
  "com.clever-age" % "play2-elasticsearch" % "0.8.2",
  "net.sourceforge.htmlunit" % "htmlunit" % "2.15",
  "commons-io" % "commons-io" % "2.4",
  "com.github.tototoshi" %% "play-flyway" % "1.1.2"
)

pipelineStages := Seq(rjs, digest, gzip)

RjsKeys.paths += ("jsRoutes" -> ("/jsroutes" -> "empty:"))

RjsKeys.paths += ("adminJsRoutes" -> ("/adminJsRoutes" -> "empty:"))

includeFilter in (Assets, LessKeys.less) := "*.less"

excludeFilter in (Assets, LessKeys.less) := "_*.less"

有人能够指出我正确的方向吗?干杯!

1 个答案:

答案 0 :(得分:3)

我已经解决了我自己的问题,不确定这是否正确,但这种方式对我有用。

  • pipelineStages:= Seq(rjs,digest,gzip) - 删除新播放中不再需要的rjs
  • 打包游戏框架的方式最近改变了playframework升级,你现在使用sbt packager来做。在这种情况下,它的“sbt docker:stage&#39;
  • 需要docker.aws.json文件将公开端口映射到aws beanstalk外部端口
  • 需要在docker文件中添加权限行,以允许beanstalk部署脚本访问目录
  • sbt packager中有一个链接到Windows的错误,因为命令行有一个字符限制被命中。这就是为什么我不能使用激活器运行本地生产模式。这个错误仍然很突出,所以我不能在自豪模式下在本地运行
  • 现在在sbt包进程中生成了docker文件,因此我将docker端口添加到sbt.build文件中。我需要找到一个命令添加到sbt.build,它将在docker文件中执行权限行,以便我们可以使用jenkins脚本自动执行该过程

我发现很少有网站对我有所帮助:

希望能帮助别人!