Reputation: 198318
Create a new sample play2 app:
play new test
Then:
cd test
play run
Visit http://localhost:9000
, we can see the default home page displayed correctly.
But when I dist it:
play dist
And upload the generated dist/test-1.0-SNAPSHOT.zip
to the server and unzip it, and run:
cd test-1.0.SNAPSHOT
./start
Then visit http://myserver:9000
, I found the css file can't be found.
GET http://myserver:9000/assets/stylesheets/main.css
404
Since the app is built-in example provided by play2, doesn't mean it's a bug of play2?
PS:
The routes
file:
# Map static resources from the /public folder to the /public path
GET /assets/*file controllers.Assets.at(path="/public", file)
And the Assets.scala
provided by play2 is:
object Assets extends Controller {
def at(path: String, file: String): Action[AnyContent] = Action { request =>
val resourceName = Option(path + "/" + file).map(name =>
if (name.startsWith("/")) name else ("/" + name)).get
if (new File(resourceName).isDirectory
|| !new File(resourceName).getCanonicalPath.startsWith(new File(path).getCanonicalPath)) {
NotFound
} else {
...
}
...
}
Seems play is trying to find a dir and a file existing on the disk, but that public
directory is packaged in test-1.0-SANPSHOT/libs/test_2.9.1-1.0-SNAPSHOT.jar
, not a real file.
Upvotes: 2
Views: 1073
Reputation: 8949
Solved for me : simply check that the file main.css is not empty.
Upvotes: 2
Reputation: 19004
It can't find that CSS file even if you do "play run", so it's nothing to do with it being packaged in a jar.
Upvotes: 1