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,
- How can i instruct jetty to tell only extract
webApp folder
into temp directory? - 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.
.