Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Embedded WAR without extracting files

First, you are using an EOL (End of Life) version of Jetty (I can tell from the class names).

Jetty 12 is the only version currently supported.

Next, nested JAR contents are not supported by Jetty or the JVM.

That means jar:file:/path/to/main.jar!/internal/path/to/alt.jar!/path/inside/altjar/

That is not going to be supported by Jetty or the JVM in the near future either.

For it to work, you'll have to have a WAR file with no nested jars, aka `WEB-INF/lib/*.jar` contents.
You could, for example, unpack all of those jars into `WEB-INF/classes` if you want to avoid it.

- Joakim

On Fri, Jul 12, 2024 at 6:59 AM Adam Retter via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
Hi there,

I have a WAR file in which I have embedded Jetty and created a simple
EmbeddedJettyServer class.

When I start the Jetty server with the
webAppContext.setExtractWAR(true) all works well so far.

I would much prefer if I could run my application without having to
extract files to a location of the user's computer.
I have tried setting setExtractWAR(false), but this causes the
following exception at Jetty startup:

java.io.FileNotFoundException: JAR entry
WEB-INF/lib/activation-1.1.1.jar!/ not found in
/Users/aretter/code/evolvedbinary/customers/cityehr/cityehr-NEW/cityehr-distribution/cityehr-standalone/target/cityehr-standalone-1.8.0-SNAPSHOT.jar
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:144)
at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:89)
at org.eclipse.jetty.webapp.MetaInfConfiguration.getTlds(MetaInfConfiguration.java:445)
at org.eclipse.jetty.webapp.MetaInfConfiguration.scanForTlds(MetaInfConfiguration.java:361)
at org.eclipse.jetty.webapp.MetaInfConfiguration.scanJars(MetaInfConfiguration.java:172)
at org.eclipse.jetty.webapp.MetaInfConfiguration.preConfigure(MetaInfConfiguration.java:106)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:488)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:523)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
at org.eclipse.jetty.server.Server.start(Server.java:423)
...

I don't think I actually need to scan for TLDs, but I don't know how
to disable that (if that is the issue). I am not using annotations as
my Webapp inside the war has a full WEB-INF/web.xml.

I did find this message -
https://bugs.eclipse.org/bugs/show_bug.cgi?id=375504 saying it's not
possible but it is from 2012, and so I am hoping things have improved
since then.

Is it now possible to run Jetty embedded in a Jar/War where the
Jar/War has jar files inside WEB-INF/lib and without extracting the
WAR file to a temporary location?

For reference my EmbeddedJettyServer class looks like this:

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

public class EmbeddedJettyServer {

  private static final Logger LOG = Log.getLogger(CityEhrJettyServer.class);

  public static void main(final String[] args) throws Exception {
    int port = 8080;
    final Server server = new Server(port);

    final WebAppContext webAppContext = new WebAppContext();

    final URL warLocation =
CityEhrJettyServer.class.getProtectionDomain().getCodeSource().getLocation();
    final Resource warResource = Resource.newResource(warLocation);

    LOG.info("Using BaseResource: {}", warResource);

    webAppContext.setExtractWAR(false); // TODO(AR) this causes a
FileNotFoundException
    webAppContext.setWarResource(warResource);


    webAppContext.setContextPath("/");
    webAppContext.setParentLoaderPriority(true);
    server.setHandler(webAppContext);

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

--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top