I have several webapps but some of them have different versions of the same jars. Can these be deployed to the same Jetty instance?
Yes; this is the reason for recommending packaging dependencies in WEB-INF/lib instead of putting them in the container's classpath. Each Web application in a container gets its own class loader and has distinct runtime instances of the classes it uses.
Related
I need to migrate from jboss to tomcat, we have two war modules and need to declare the dependency between the two deployments in order for the libraries to be accessible by both the separate war files.
requirement arises due to licensing issues around the packaging of jar files in internal binaries.
I'd like to know the best way to load shared jars into Tomcat so that two or more WAR's deployed in Tomcat are able to access Spring Beans from common jars without any issues.
When I'm deploying more than one WAR into Tomcat, beans in common jars are getting overwritten every time an application is deployed. How can I configure or load common jars that every application deployed in Tomcat gets its own set of beans without overwriting any other application beans.
I'm loading common jars from shared path.. Tomcat loads jar from its lib directory, then from shared location then from WEB-INF/lib[.war] and so on... My Question here is, how to load jars which are shared between multiple web applications. I also wanna ensure that spring beans loaded in one application context are isolated from others.
I am not sure whether I understand your meaning. In java web, the jars are loaded by class loader based on some strategy. If your jars are in lib directory of tomcat, every application deployed in this tomcat can load these jars from tomcat lib directory.
And if the jars are in your war packages, every application will load from it own war package.
In the normal, we will not put any jars into tomcat lib by ourselves.
I have two WAR files that i need to deploy on a server.
the catch is that i cant run another tomcat on that server.
deploying two WAR files is easy but, is it possible to run them both while one of them uses
Spring 3.8
and the other one uses
Spring 4.1.4
which is the latest version?
Will it conflict?
answers like "try it out" are acceptable :) but i need to know for sure so i wont have issues in the future.
Thanks
See the following for an explanation of how Tomcat's classloading mechanism works:
http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
WebappX — A class loader is created for each web application that is
deployed in a single Tomcat instance. All unpacked classes and
resources in the /WEB-INF/classes directory of your web application,
plus classes and resources in JAR files under the /WEB-INF/lib
directory of your web application, are made visible to this web
application, but not to other ones.
If, then, the Spring Jar files are bundled in WEB-INF/lib for each application then you will have no issues. An issue would only arise if they were in some shared location.
two different application under tomcat has two diffferent classpath and classloader so they don't conflict
latest as of today is 4.2.0 (under dev), you can keep track at http://projects.spring.io/spring-framework/
I have a Spring webapp running in Glassfish 3.1.2. I am just beginning to convert the webapp to OSGi. I undeployed the existing webapp and copied the spring and gemini OSGi jars into the modules directory in the Glassfish installation. I then installed and activated them using the Glassfish OSGi web console (which I understand to be some sort of customised Felix web console) and everything was fine. It didn't do anything but I could install and activate them in the web console which is what I wanted to test.
I then started to redeploy the non-OSGi jars of my existing webapp using the Glassfish Application console to see if the 2 type of jars could coexist, which, given my understanding of OSGi I thought they should be able to. At this point NoClassDefFoundErrors started getting thrown complaining about not being able to find org.apache.commons.logging amongst other classes. These class were present in both the Module directory as the installed OSGi jars and the application classpath. I then deactivated the jars in the console but didn't remove the the OSGi jars but the exceptions continued to be thrown.
I got a classloader print out and found that the jars in the WEB-INF of my webapp weren't getting loaded but I wasn't sure whether this was the problem or a symptom.
I then removed the jars from the uninstalled the OSGi jars and everything started working again and the webapp could be deployed.
Can anyone think of any reason why this might happen? I am guessing that the content of the module directory is on the classpath but if so why? How would I prevent this from causing problems if I want OSGi and non-OSGi jars to work together?
Side Notes
When I viewed the classes getting loaded by the classloader I couldn't see content form the modules folder getting loaded.
I can install and activate the OSGi jars after the the non-OSGi jars are deployed but not the other way round.
( Disclaimer: I do not have specific experience with glassfish, but JBoss and other
strange environments sporting classloader hierarchies)
You have to be carefull with classloader hierarchies in java - the same bytecode equal class will not be equal or asignable to if comes from another classloader, and while loading classes it is important to find dependencies through loading classloader or his parents.
To resolve your situation you will have to carefully examine this hierarchy and check settings for delegation and class resolution ( like parent first / self first ).
JBoss tried to solve this problem by introducing unified classloader which resulted in one big pile of assorted classes and leaks of resources between contexts / webapps in default setting.
I've got the following scenario:
On the one hand, I've got a tomcat instance with a lot of applications that need the activemq-all.jar which contains slf4j libraries, so I've deployed it into the lib directory, it is not optional for me to include this jar file on each app.
On the other hand I need to install a monitor application which I can't control and ships with a different version of slf4j.
Running the last application on another tomcat instance is also not an option.
I would like to configure tomcat's ClassLoader to try and load first the jars on the webapps and then the jars on the lib/ directory.
Is this possible? How can be achieved?
By Default tomcat loads the web app classes first and gives them a higher preference than classes in its own lib directory. You can keep the mentioned jar is the lb folder. Typically i would recommend the catalina_base directory
Load the common jars under the Common class loader. By default, the common class loader looks for jars under:
$CATALINA_BASE/lib
$CATALINA_HOME/lib
Any jars packaged with you web app should take precedence over those found in the Common class loader.