4

I'm using Jetty 8.1.9 as an API and manually deploying by adding a WebAppContext handler to the server.

Server server = new Server();

WebAppContext webapp = new WebAppContext();
webapp.setContextPath(CONTEXT_PATH);
webapp.setWar(WEBAPP_PATH);
webapp.setExtractWAR(false);
server.setHandler(webapp);

server.start();
server.join();

If the webapp does not contain any jars in WEB-INF/lib, then this works just fine. However, if the webapp contains jars, I get the following exception:

java.lang.IllegalArgumentException: !file: jar:file:/F:/projects/jetty-example/webapps/app.war!/WEB-INF/lib/whatever.jar
    at org.eclipse.jetty.webapp.WebAppClassLoader.addClassPath(WebAppClassLoader.java:245)

It works if I set webapp.setCopyWebInf(true);

Am I doing it wrong, is it a bug, or can Jetty not load libraries directly from wars?

Edit:
To provide a little more information about my setup, Jetty is embedded inside of a jar with a main class that sets everything up, similar to start.jar. This is intended to be a simplification (a facade, if you will) of a standard jetty deployment. Only specific war packages will be used, but as they are potentially optional, they are external to the executable jar. So, the directory structure looks something like the following:

/ baseDirectory
  | embedded-jetty.jar
  / webapps
    | myWar1.war
    | myWar2.war
Shaun
  • 2,490
  • 6
  • 30
  • 39
  • Before I post and answer I wanted to make sure you are trying to put jetty inside of the war itself and start it all with something like java -jar foo.war? If that isn't the case please explain a bit more of your setup in that regard. – jesse mcconnell Mar 05 '13 at 18:36
  • Not quite. Updated my question to clarify. – Shaun Mar 06 '13 at 12:01
  • So you have wars inside of a jar? if so, just unpack those war files as /webapps/myWar1 and /webapps/myWar2 inside of your baseDirectory.jar – Joakim Erdfelt Mar 14 '13 at 14:28
  • Actually, it's jars inside of a standard war, which seems to cause Jetty's WebAppClassLoader to fizzle out unless at least the jars are extracted from the war at runtime. – Shaun Mar 15 '13 at 04:09

1 Answers1

4

It looks like you have to set webapp.setCopyWebInf(true); according to this page from jetty jira.

ericson
  • 1,658
  • 12
  • 20
  • I stumbled across that before. It doesn't seem to explicitly state that you shouldn't be able to load the .jars directly from the wars, or why. Still, you may be right. – Shaun Mar 08 '13 at 15:16