Reputation: 4811
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,
webApp folder
into
temp directory?I am newbie to jetty please let me know how to do this.
.
Upvotes: 0
Views: 581
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