Note that there are some explanatory texts on larger screens.

plurals
  1. POScalatra loading static content from executable jar file
    primarykey
    data
    text
    <p>In my build.sbt I have:</p> <pre><code>resourceDirectory in Compile &lt;&lt;= baseDirectory(_ / "src/main/webapp") </code></pre> <p>This is my JettyLauncher.main:</p> <pre><code> def main(args: Array[String]) { val port = if(System.getenv("PORT") != null) System.getenv("PORT").toInt else 8080 println(s"JettyLauncher: ${port}") val server = new Server(port) val context = new WebAppContext() context setContextPath "/" context.setResourceBase("src/main/webapp") context.addServlet(classOf[MyServlet], "/*") server.setHandler(context) server.start server.join } </code></pre> <p>In the <code>notFound</code> method I have:</p> <pre><code>notFound { // remove content type in case it was set through an action contentType = null serveStaticResource() getOrElse &lt;h1&gt;Not found. Bummer.&lt;/h1&gt; } </code></pre> <p>The webservices are accessible, and work as I expect, but the static content (in this case index.html) isn't being found, when I launch my application with</p> <pre><code>java -jar myapp.jar </code></pre> <p>I have a feeling I need to write my own <code>serveStaticResource</code> function, but I am hoping not.</p> <p>This is what I see, and the HTTP 200 is due to the 'bummer' response of not finding the file:</p> <pre><code>09:13:44.735 [qtp874703452-16 - /index.html] DEBUG org.eclipse.jetty.server.Server - REQUEST /index.html on AsyncHttpConnection@fb4871b,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-5,l=14,c=0},r=3 09:13:44.748 [qtp874703452-17] DEBUG org.eclipse.jetty.http.HttpParser - filled 0/0 09:13:44.752 [qtp874703452-16 - /index.html] DEBUG o.e.j.server.handler.ContextHandler - scope null||/index.html @ o.e.j.w.WebAppContext{/,file:/C:/Users/src/main/webapp} 09:13:44.759 [qtp874703452-16 - /index.html] DEBUG o.e.j.server.handler.ContextHandler - context=||/index.html @ o.e.j.w.WebAppContext{/,file:/C:/Users/src/main/webapp} 09:13:44.764 [qtp874703452-16 - /index.html] DEBUG org.eclipse.jetty.server.session - sessionManager=org.eclipse.jetty.server.session.HashSessionManager@5f8b459a 09:13:44.768 [qtp874703452-16 - /index.html] DEBUG org.eclipse.jetty.server.session - session=null 09:13:44.771 [qtp874703452-16 - /index.html] DEBUG o.e.jetty.servlet.ServletHandler - servlet ||/index.html -&gt; gov.ornl.cyber.botmon.ui.BotMonServlet-1 09:13:44.774 [qtp874703452-16 - /index.html] DEBUG o.e.jetty.servlet.ServletHandler - chain=null 09:13:44.813 [qtp874703452-16 - /index.html] DEBUG org.eclipse.jetty.server.Server - RESPONSE /index.html 200 handled=true </code></pre> <p>How do I configure the Jetty Launcher so it will properly find the static files?</p> <p>Is there a way to tell it that src/main/webapp is a resource folder?</p> <p>The other problem I have is that in the <code>notFound</code> function I don't see how to know which file wasn't found so I can then just call <code>this.context.getResource("src/main/webapp" + missingfile)</code> myself, from withing Scalatra. I think that is the root of my difficulty is that I don't now which file was not found.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload