Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Technical details of serve modules without publishing in Eclipse WTP and Tomcat?

Eclipse's Web Tools Platform (WTP) allows you to configure Tomcat to "Server modules without publishing":

Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader.

In a 5 step process (just joking, you pick the # of steps), what happens technically and where are the files that Eclipse generates? I did notice that Eclipse generated a org.eclipse.jst.server.tomcat.runtime.70.loader.jar file in the Tomcat lib directory.

like image 266
Josh Unger Avatar asked Mar 22 '13 16:03

Josh Unger


1 Answers

The idea is to serve a web application directly from the scattered directory structure of the development workspace, without packaging modules into JARs which then end up in WEB-INF/lib in a WAR.

The main benefits are:

  • You don't need to build archives.
  • When you change a resource in your workspace, the change is reflected in the running webapp without redeploying the webapp or restarting the server.

With Servlet 3.0, web resources may also be bundled in library JARs in META-INF/resources, so classes and resources may come from multiple workspace directories.

Tomcat 7.0 supports a VirtualWebappLoader and a VirtualDirContext to configure a web application based on a collection of scattered resource and class directories.

To serve your web app directly from your Eclipse workspace, WTP generates a suitable Tomcat configuration matching your project structure in $WORKSPACE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/conf/server.xml

For some reason, WTP does not directly use the Tomcat loader and context implementations but has its own WtpDirContext and WtpWebappLoader which are slightly different but similar. (I believe this approach is older than the current solution in Tomcat. There is some special logic for TLD scanning - I'm not sure if this is still required with the latest Tomcat versions.) These helper classes are contained in the org.eclipse.jst.server.tomcat.runtime.70.loader.jar you noticed.

Without Serve modules without publishing, when you change a web resource in META-INF/resources in a library module, this change will not be directly visible in the running application after reloading the current page in the browser.

like image 164
Harald Wellmann Avatar answered Nov 06 '22 07:11

Harald Wellmann