Play Framework 2.3.7: Static assets location not working in production

I have seen a few questions on this but cant seem to get to the bottom of it.

I have a Play Framework 2.3.7 (Activator 1.2.12) site, when I run it in dev mode everything works fine. When I start it in production mode I get the following errors:

 [app] $ start
 [info] Wrote C:UsersAppgitwebsite2.0targetscala-2.10app_2.10-1.0-
 SNAPSHOT.pom
 [info] Main Scala API documentation to C:UsersAppgitwebsite2.0targetscala-
 2.10api...
 [info] Compiling 57 Scala sources and 58 Java sources to C:UsersAppgitwebsit
 e2.0targetscala-2.10classes...
 [error] C:UsersAppgitwebsite2.0targetscala-2.10twirlmainviewshtmladmi
 nsharedfoot.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:UsersAppgitwebsite2.0targetscala-2.10twirlmainviewshtmladmi
 nsharedhead.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:UsersAppgitwebsite2.0appviewsadminsharedfoot.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:UsersAppgitwebsite2.0appviewsadminsharedhead.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:UsersAppgitwebsite2.0targetscala-2.10twirlmainviewshtmlhome
 .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:UsersAppgitwebsite2.0appviewshome.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:UsersAppgitwebsite2.0targetscala-2.10twirlmainviewshtmlshar
 edfoot.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:UsersAppgitwebsite2.0targetscala-2.10twirlmainviewshtmlshar
 edhead.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:UsersAppgitwebsite2.0appviewssharedfoot.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:UsersAppgitwebsite2.0targetscala-2.10twirlmainviewshtmlshar
 ednav.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:UsersAppgitwebsite2.0appviewssharedhead.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:UsersAppgitwebsite2.0appviewssharednav.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:UsersAppgitwebsite2.0targetApp-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.

The issue seems to be around the requirejs and its asset path. The code for the first footer error is as follows:

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

My routes file for assets is:

# 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)

Here is my 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"

Is anyone able to point me in the right direction? Cheers!


I have got a solution to my own problem, not sure if this is the correct way or not but that way that worked for me.

  • pipelineStages := Seq(rjs, digest, gzip) - Removed rjs as its no longer required in the new Play
  • the way to package the play framework was changed recently with the playframework upgrades, you now use the sbt packager to do it. in this case its 'sbt docker:stage'
  • the docker.aws.json file is required to map the exposed port to the aws beanstalk external port
  • a permission line needs to be added the docker file to allow the beanstalk deployment script access to the directory
  • there is a bug in the sbt packager that linked to windows in that the command line has a character limit thats getting hit. Thats why I cant run a local production mode using activator. This bug is still outstanding so I cant run it locally in proudction mode
  • the docker file is now generated in the sbt package process so I added the docker ports to the sbt.build file. I need to find a command to add to the sbt.build which will do the permission line in the docker file so that we can use the jenkins script to automate the process
  • Few sites I found that really helped me:

  • http://www.ronaldcirka.com/blog/2014/12/06/deploying-play-framework-to-elastic-beanstalk-in-docker/
  • Why I receive permission denied in Docker deployment?
  • Best way to deploy play2 app using Amazon Beanstalk
  • Hope that helps someone!

    链接地址: http://www.djcxy.com/p/23766.html

    上一篇: Cython不识别c ++ 11命令

    下一篇: Play Framework 2.3.7:静态资产位置在生产中不起作用