Standalone jar with embedded jetty

(Martin) #1


I would like to create a standalone jar with an embedded jetty. So I have a main method which creates a WebAppContext The web.xml is located in src/main/webapp/WEB-INF):

    val web = new WebAppContext("src/main/webapp", "/")

Now I wonder how to easily create a fatjar and what’s the best way to do it to get my app load the web.xml. Should I copy the WEB-INF folder directly in the root dir of the jar like it is done by a war? Or should I better create a standalone war instead of a jar. What are your thoughts about that?


(Luke Daley) #2

If you truly want to embed Jetty, you need to create a jar.

Most people create the war, then copy that war as-is into the jar and simply load it as a classpath resource.

(Martin) #3

ah, ok thx. Actually I just switched to socko which uses netty. In that constellation I don’t need a web.xml and all that stuff any more :slight_smile: and can easily use the installApp task. But thx for your reply. Btw you wrote ‘If you truly want to embed Jetty…’ what would be your advice instead to get a simple scala rest app running standalone?

(Luke Daley) #4

I’d go with Socko, it looks pretty good.