gihan-maduranga
gihan-maduranga

Reputation: 4811

How to tell jetty to extract part of the jar files into its context temp location

I have embedded Jetty into my Java application and i create a executable jar file.When i execute jar file from cmd jetty server is started.I defined following in Jetty server starter class.

protected void configureWebApp() throws IOException {
        File webAppDir=new File(getClass().getProtectionDomain().getCodeSource().getLocation());

      WebAppContext context = new WebAppContext(webAppDir.getPath(), "/");
        resetTempDirectory(context, currentDir);
        context.setInitParameter("development", "false");
        server.setHandler(context);
        }

protected void resetTempDirectory(WebAppContext context, File currentDir) throws IOException {
        File workDir;
        if (workPath != null) {
            workDir = new File(workPath);
        } else {
            workDir = new File(currentDir, "work");
        }
        FileUtils.deleteDirectory(workDir);
        context.setTempDirectory(workDir);
    }

when running from cmd webAppDir set path pointed to my application jar.so jetty will extract all jar content into its temp directory.It seems like i wasting the resource and slow down my application startup.

Inside my jar it has a webApp folder that contains the web releated stuff.My questions are,

  1. How can i instruct jetty to tell only extract webApp folder into temp directory?
  2. I can turn off the jetty extraction into temp directry and write my own method to extract folder i needed and point that folder as jetty temp directory.I am not sure if this a good idea.

I am newbie to jetty please let me know how to do this.

.

Upvotes: 0

Views: 581

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49515

So you want to not allow the Servlet Spec temp directory to do its thing, but still use the Servlet Spec?

See prior answer on how the temp directory works.

Option #1

This is embedded-jetty, skip the WebAppContext (and its Servlet Spec mandated behavior) and configure everything via Handlers (like the ServletContextHandler).

You'll lose some ability to "discover" components, and have no bytecode scanning, but you'll be in ultimate control and startup will be measured in sub-second timing.

Option #2

If this is just a startup issue, then ignore the temp directory issue, run the quickstart generation of the servlet manifest before you deploy, and start your WebAppContext using the (prebuilt) quickstart metadata.

Upvotes: 1

Related Questions