• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Classloading in Tomcat AS 7

 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I have probably a basic question for which I need some clarification.

I have a web application, which i making use of some web framework GWT.

I am building my application using Maven where my pom files contains a plugin definition for the web framework it needs:



The application builds successfully and the .war file is generated.

If I look inside the war archive, it contains framework specific jars plus others inside /WEB-INF/lib/*.jar of my web application. So far everything is good and as per my understanding.

Afterwords I deploy the war file on Tomcat AS 7 successfully.

Now my question is what if on the Tomcat AS7 under $CATALINA_HOME/lib there are framework (gwt) specific jars also available/copied. And on top of it, let's say the version of the framework specific jars is different between /WEB-INF/lib/ and $CATALINA_HOME/lib.

My question is during my web application run, the classloader would use the framework (GWT) specific jars from which location /WEB-INF/lib/ OR $CATALINA_HOME/lib?

I know ideally we should NOT place web application specific jars as part of the $CATALINA_HOME/lib, but lets assume it is the case and now I need to know which location is the default for the application run?

Thanks.
 
Bartender
Posts: 21732
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ideally", huh!

If you put ANY jar in TOMCAT_HOME/lib that isn't designed to live in such an environment you are pretty much guaranteed an unstable webapp and possibly even an unstable Tomcat.

Tomcat's docs should outline classpaths, but there's a catch. Tomcat has maybe half-a-dozen or so DIFFERENT classpaths, depending on what context code is executing under. and that's not even considering specifically that each webapp has its own classpath. If you initiate a process under one classpath, and then do further work under a different classpath, you can end up with class data that's all scrambled.

Even allowing for that, Java wasn't designed with the idea of "overlay" class loading. To operate reliably, there should be exactly one and ONLY one instance of a class in the classpath(s), whether you've got a simple app, applet, or complex webapp server.

If the GWT docs explicitly tell you you can/should put the GWT jars in the TOMCAT_HOME/lib directory then that means that GWT was written to run as a multi-app resource. In which case, copy the affected libs into TOMCAT_HOME/lib and set your Maven POM to list them as "provided" instead of "compile".

If the GWT docs do NOT explicitly tell you this, then assume the worst and don't attempt to share the GWT libraries. Build them into the WAR using the "compiled" POM context.
 
Norman Meister
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

What would be the default behaviors of the Tomcat AS? Or in other words, if I download a fresh copy of Tomcat AS, put in the TOMCAT_HOME/lib the GWT jars and then deploy my web application that also has the same (recent version) GWT jars in its web-inf/lib folder.

So when the application would run, which jars would be in in use?

I need to know from a default classloading behavior point of view.



Tim Holloway wrote:"Ideally", huh!

If you put ANY jar in TOMCAT_HOME/lib that isn't designed to live in such an environment you are pretty much guaranteed an unstable webapp and possibly even an unstable Tomcat.

Tomcat's docs should outline classpaths, but there's a catch. Tomcat has maybe half-a-dozen or so DIFFERENT classpaths, depending on what context code is executing under. and that's not even considering specifically that each webapp has its own classpath. If you initiate a process under one classpath, and then do further work under a different classpath, you can end up with class data that's all scrambled.

Even allowing for that, Java wasn't designed with the idea of "overlay" class loading. To operate reliably, there should be exactly one and ONLY one instance of a class in the classpath(s), whether you've got a simple app, applet, or complex webapp server.

If the GWT docs explicitly tell you you can/should put the GWT jars in the TOMCAT_HOME/lib directory then that means that GWT was written to run as a multi-app resource. In which case, copy the affected libs into TOMCAT_HOME/lib and set your Maven POM to list them as "provided" instead of "compile".

If the GWT docs do NOT explicitly tell you this, then assume the worst and don't attempt to share the GWT libraries. Build them into the WAR using the "compiled" POM context.

 
Tim Holloway
Bartender
Posts: 21732
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norman Meister wrote:
So when the application would run, which jars would be in in use?



ALL of them. That's what makes it so dangerous.

I repeat: Java wasn't designed with the idea of "overlay" class loading. The classpath loader doesn't load "jars", it loads classes and it gets those classes from whatever sources the classloader(s) that are in effect supply them from. That includes the ability to actually synthesize a class from code without any backing file of any sort as well as the more common things like pulling classes in via URL data sources.


To operate reliably, there should be exactly one and ONLY one instance of a class in the classpath(s), whether you've got a simple app, applet, or complex webapp server. If there is not, results cannot be guaranteed.
 
I'm doing laundry! Look how clean this tiny ad is:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!