Search code examples
jakarta-eejbossclassloaderjboss5.x

JBoss classloading when 2 WARs have the same class


I have a web applications A.war which has two servlets AServlet and BServlet. Both instantiate a helper class com.mycompany.Foo.class (this is my own class, not a third party library).

Now I want to split the two servlets into two separate WARs: A.war will have only AServlet and a new B.war will have BServlet. AServlet will invoke BServlet via HTTP GET. Both WARs will have com.mycompany.Foo.class. I want to deploy both WARs on the same JBoss instance.

The question is, will there be any classloading issues due to the same class being present in both WARs, and the WARs being deployed on the same JBoss instance?


Solution

  • No, you shouldn't experience any problem. By default the web application class loader works different from the Java2 delegation model: when a web application's needs a class first it will look in the local repositories (that is the classes and libraries in the wEB-INF/classes or WEB-INF/libs directories) instead of delegating. So, the configuration you're proposing will work without any problem.

    But since both wars will contain the same class, have you considered packaging this class in a jar and place it in the jboss instance lib directory? This way you wouldn't need to include it in all the web applications you deploy in the instance.

    Take a look at Jboss documentation here.