我刚刚从UI加载了Play Java Seed来创建一个新的应用程序。我在public/stylesheets/main.css
中写了一些CSS代码,这是我对这个项目的唯一改变。在编译并运行应用程序后,Chrome控制台会显示
GET http://localhost:9000/assets/stylesheets/main.css 404 (Not Found)
GET http://localhost:9000/assets/javascripts/hello.js 404 (Not Found)
我已阅读资产控制器文档here,但无法弄清楚我出错的地方。
在我的main.scala.html
文件中(与种子相同),我有:
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/hello.js")" type="text/javascript"></script>
</head>
在我的路线文件中(也与种子保持不变):
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
favicon显示在选项卡中,但当我转到http://localhost:9000/assets/images/favicon.png
时,页面也不可用,就像使用main.css和hello.js脚本一样。
答案 0 :(得分:2)
当从由以下创建的打包的tarball运行时,似乎也发生了(在游戏2.3.8中)
$ activator universal:package-zip-tarball
,然后..
$ [tarball-extract-path]/bin/[project-name]
在本地开发构建文件下载正常,但在远程测试服务器上我得到404(未找到)。
答案 1 :(得分:1)
对我来说,当我开始制作项目时问题就消失了:
activator start
这只是一种解决方法,但我希望它可以帮助你们中的一些人。
我怀疑这是一个游戏中的错误,并希望在新游戏版本上消失。
答案 2 :(得分:-1)
如果您的版本中有LessKeys.compress := true
,则您必须使用缩小版。
@routes.Assets.at("stylesheets/main.min.css")
答案 3 :(得分:-2)
运行从使用PlayFramework 2.3.7的typesafe.com下载的播放Java种子时,我没有任何问题
看看我做了什么并做同样的事情
$ unzip play-java.zip
Archive: play-java.zip
inflating: play-java/conf/application.conf
inflating: play-java/conf/routes
inflating: play-java/README
inflating: play-java/activator
inflating: play-java/app/views/main.scala.html
inflating: play-java/app/views/index.scala.html
inflating: play-java/app/controllers/Application.java
inflating: play-java/test/ApplicationTest.java
inflating: play-java/test/IntegrationTest.java
inflating: play-java/project/plugins.sbt
inflating: play-java/project/build.properties
inflating: play-java/LICENSE
inflating: play-java/.gitignore
inflating: play-java/public/stylesheets/main.css
inflating: play-java/public/javascripts/hello.js
inflating: play-java/public/images/favicon.png
inflating: play-java/build.sbt
inflating: play-java/activator.bat
inflating: play-java/activator-launch-1.2.12.jar
$ cd play-java/
$ ls
activator* activator.bat* activator-launch-1.2.12.jar app/ build.sbt conf/ LICENSE project/ public/ README test/
$ activator run
[info] Loading project definition from /home/skierat/Documents/dev/projects/typesafe/play-java/project
[info] Updating {file:/home/skierat/Documents/dev/projects/typesafe/play-java/project/}play-java-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading http://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.play/sbt-plugin/scala_2.10/sbt_0.13/2.3.7/jars/sbt-plugin.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#sbt-plugin;2.3.7!sbt-plugin.jar (3451ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/build-link/2.3.7/build-link-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#build-link;2.3.7!build-link.jar (534ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-exceptions/2.3.7/play-exceptions-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-exceptions;2.3.7!play-exceptions.jar (527ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/routes-compiler_2.10/2.3.7/routes-compiler_2.10-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#routes-compiler_2.10;2.3.7!routes-compiler_2.10.jar (2230ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/sbt-run-support_2.10/2.3.7/sbt-run-support_2.10-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#sbt-run-support_2.10;2.3.7!sbt-run-support_2.10.jar (652ms)
[info] Done updating.
[info] Set current project to play-java (in build file:/home/skierat/Documents/dev/projects/typesafe/play-java/)
[info] Updating {file:/home/skierat/Documents/dev/projects/typesafe/play-java/}root...
[info] Resolving jline#jline;2.11 ...
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play_2.11/2.3.7/play_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play_2.11;2.3.7!play_2.11.jar (6448ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-java_2.11/2.3.7/play-java_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-java_2.11;2.3.7!play-java_2.11.jar (768ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-java-jdbc_2.11/2.3.7/play-java-jdbc_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-java-jdbc_2.11;2.3.7!play-java-jdbc_2.11.jar (550ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-java-ebean_2.11/2.3.7/play-java-ebean_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-java-ebean_2.11;2.3.7!play-java-ebean_2.11.jar (655ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-cache_2.11/2.3.7/play-cache_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-cache_2.11;2.3.7!play-cache_2.11.jar (775ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-java-ws_2.11/2.3.7/play-java-ws_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-java-ws_2.11;2.3.7!play-java-ws_2.11.jar (661ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-iteratees_2.11/2.3.7/play-iteratees_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-iteratees_2.11;2.3.7!play-iteratees_2.11.jar (4162ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-json_2.11/2.3.7/play-json_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-json_2.11;2.3.7!play-json_2.11.jar (1627ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-functional_2.11/2.3.7/play-functional_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-functional_2.11;2.3.7!play-functional_2.11.jar (1132ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-datacommons_2.11/2.3.7/play-datacommons_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-datacommons_2.11;2.3.7!play-datacommons_2.11.jar (526ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-jdbc_2.11/2.3.7/play-jdbc_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-jdbc_2.11;2.3.7!play-jdbc_2.11.jar (891ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-ws_2.11/2.3.7/play-ws_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-ws_2.11;2.3.7!play-ws_2.11.jar (1746ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-test_2.11/2.3.7/play-test_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-test_2.11;2.3.7!play-test_2.11.jar (773ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-docs_2.11/2.3.7/play-docs_2.11-2.3.7.jar ...
[info] [SUCCESSFUL ] com.typesafe.play#play-docs_2.11;2.3.7!play-docs_2.11.jar (8607ms)
[info] Done updating.
--- (Running the application, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
最后的测试:
$ curl -Is http://localhost:9000/assets/stylesheets/main.css | head -n 1
返回
HTTP/1.1 200 OK