How does jetty figures out whether to expand a war

2019-09-10 06:09发布

问题:

I am using Jetty server for for my web application. does jetty always expand a war file on server start? if not the how can i make it do so? lets say after first time start/deployment, now if i replace the war file to an old war file, jetty does not expand old war file.

回答1:

By default, Jetty always expands WAR files.

You can configure it to not expand by using the extractWAR in your advanced configuration descriptor file.

However, what I think you are actually asking about, is how does the web app / servlet spec temp directory logic work?

The tempDirectory used by Jetty is determined by a number of factors, mostly dictated by the servlet spec. See prior answer about the topic of tempDirectory configuration for details.

When the temp directory is unspecified / unconfigured a new temp directory is created using the following rough syntax.

File tempDir = new File(System.getProperty("java.io.tmpdir") +
   File.separator + "jetty-" + host + "-" + port + "-" + 
   resourceBase + "-_" + context + "-" + virtualhost + "-" + randomdigits +
   ".dir");

The temp directory used is persisted, meaning it is not deleted on server shutdown. The temp directory is used to unpack the WAR into when the WAR file (or context deployable XML) is determined to be newer than the content in the persisted temp directory.

Starting with Jetty 9.1, there is now a WebAppContext.setPersistTempDirectory(boolean) that can be used to turn off the temp directory persistence.