I'm using the scalatra documentation and the sbt-assembly plugin to create a stand-alone jar. It works on my local machine (Debian Wheezy with OpenJdk 1.7.0), but fails on the remote EC2 machine (Ubuntu 12.04.2 LTS) running the same Jdk.
The exception message is:
org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [index.ssp]; are you sure it's within [/home/abc/src/main/webapp]?
at org.fusesource.scalate.servlet.ServletResourceLoader.createNotFoundException(ServletResourceLoader.scala:79)
at org.fusesource.scalate.util.ResourceLoader$class.resourceOrFail(ResourceLoader.scala:55)
at org.fusesource.scalate.servlet.ServletResourceLoader.resourceOrFail(ServletResourceLoader.scala:37)
at org.fusesource.scalate.util.UriResource.delegate(Resource.scala:91)
at org.fusesource.scalate.util.DelegateResource.text(Resource.scala:216)
at org.fusesource.scalate.ssp.SspCodeGenerator.generate(SspCodeGenerator.scala:152)
at org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:750)
at org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:699)
at org.fusesource.scalate.TemplateEngine.liftedTree1$1(TemplateEngine.scala:419)
It says it cannot find the view, but the exact same jar file works on my local machine.
You need to set the correct resource base on the embedded Jetty. Here are three options:
attach resources to .jar file, by following the instructions in https://stackoverflow.com/a/17913254/1590415
put the resources in a folder on the filesystem
use the
scalatra-sbt
plugin, it has adist
task which creates a .zip distribution. For a working project see here. You can call the task by typingdist
on the SBT prompt.In my experience Jetty loads web resources from a .jar really slow, so you may be better off putting them in a folder on the filesystem. Option 2 and 3 both load the resources from the filesystem.