Sunday, 11 August 2013

Load webapp from the compiled jar file with embedded Tomcat 7

Load webapp from the compiled jar file with embedded Tomcat 7

I usually develop web application using embedded jetty server and wrap
them in .exe file using applications like Launcher4j. I like to put my web
application folder inside a java package and read it from there instead of
putting it in a folder next to the generated .exe file. I like to do so to
protect my webapp from being edited. With an embedded jetty server it is
done like this:
String jetty_home =
MyClass.class.getClassLoader().getResource(webappsClassPath).toExternalForm();
WebAppContext webapp = new WebAppContext();
webapp.setServer(server);
webapp.setContextPath(contextPath);
webapp.setResourceBase(jetty_home + "/webapps/MyWebapp");
webapp.setWar(webappsFolder);
webapp.setParentLoaderPriority(true);
How can I manage the same with an embedded Tomcat 7 or Tomcat 8-alpha
server? Thank you! :)

No comments:

Post a Comment