Menu

#61 One-JAR is incompatible with Jetty

open
nobody
None
5
2014-08-25
2011-03-08
No

I want to use OneJar to create a jar which runs a web server. I can run the web server from within Eclipse, which starts up on port 8080 and displays the text "hello world". However, I can't figure out how to get it to run from a standalone jar. I've attached the source code for a minimal reproduction case. It uses the one jar Maven plugin, so simply run "mvn package" to create the Jar.

2011-03-07 20:01:47.241:WARN::Failed startup of context o.e.j.w.WebAppContext{/,null},jar:file:/test-0.0.1-SNAPSHOT.one-jar.jar!/main/test-0.0.1-SNAPSHOT.jar!/
java.io.FileNotFoundException: jar:file:/test-0.0.1-SNAPSHOT.one-jar.jar!/main/test-0.0.1-SNAPSHOT.jar!/
at org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:471)
at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:49)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:406)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:435)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:258)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at com.benmccann.test.App.run(App.java:33)
at com.benmccann.test.App.main(App.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)

Discussion

  • Benjamin McCann

    Benjamin McCann - 2011-03-08
     
  • P. Simon Tuffs

    P. Simon Tuffs - 2011-03-08

    This is a non-trivial problem to fix, and I have no solution handy.
    What might work for you is to expand the webapp using the
    One-Jar-Expand mechanism, ugly but should circumvent the filesystem
    centric nature of servlet containers. Thanks for the example, I will
    take a look when I get some time, but that won't be for a few weeks.

     
  • Benjamin McCann

    Benjamin McCann - 2011-03-09

    I upgraded to the release candidate for Jetty (version 8.0.0.M2) and am now getting a new error. I was wondering if you had any ideas on this one? Is it possible to read an xml file from a jar within a jar? The error message makes no sense to me because it looks like that file is there.

    java.io.FileNotFoundException: JAR entry lib/jetty-webapp-8.0.0.M2.jar!/org/eclipse/jetty/webapp/webdefault.xml not found in /home/bmccann/workspace/news/main/build/libs/frontend-1.0-standalone.jar
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:140)
    at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:187)
    at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:203)
    at org.eclipse.jetty.webapp.Descriptor.parse(Descriptor.java:60)
    at org.eclipse.jetty.webapp.WebDescriptor.parse(WebDescriptor.java:142)
    at org.eclipse.jetty.webapp.MetaData.setDefaults(MetaData.java:117)
    at org.eclipse.jetty.webapp.WebXmlConfiguration.preConfigure(WebXmlConfiguration.java:46)
    at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:465)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:495)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
    at org.eclipse.jetty.server.Server.doStart(Server.java:244)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at com.slice.news.frontend.server.WebServer.run(WebServer.java:100)
    at com.slice.news.frontend.server.WebServer.main(WebServer.java:131)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.simontuffs.onejar.Boot.run(Boot.java:351)
    at com.simontuffs.onejar.Boot.main(Boot.java:156)

     
  • Stig Kleppe-Jorgensen

    Why not just use one of the many examples of creating an executable war? For example: https://github.com/mkrabset/gradle-execwar-plugin.

    This makes it possible to start the web-app in an embedded Jetty like this:

    java -jar <war file>

     

Log in to post a comment.