开发者

Deploying 2 war files with common classes in JBoss

I have two war file app1.war and app2.war deployed in a single JBoss instance. Package names for java classes for both war files starts with com.myapp

To add further, there are some Classes that are common between the two apps while there are some that have same fully q开发者_运维技巧ualified class names but are different (Source Code has changed).

I want to know, if this could pose threat of any kind to the deployment scenario?


You could get class loading problems if your applications are not isolated, i.e. have their own class loading repository and class loaders. If you configure JBoss to isolate the applications from each other you should be fine (I don't know what is the default for your version but 4.2.3 that we use does not isolate apps by default).

To clarify that a bit:

If you have two classes with different implementations but the same FQCN you could get the wrong class from the class loader for the application that is loaded second. Even if the implementation was the same you could get class cast exceptions or other strange behavior if one app gets the class from the other app.


I had a similar situation with multiple apps.Look at my solution here


Best way is to isolate class loading for your application archives.

For JBoss 5.1.0 GA following worked for me.

  1. Create jboss-classloading.xml file in WEB-INF folder.
  2. Added following lines to this file

Here, export-all="NON_EMPTY" => Makes sure the classes loaded for this app is not exported import-all="true" => Imports and uses all of the class definition available. parent-first="false" => If more than one class with same name is found, one defined under the application will be used first.

FYI. This also helped me embedding the log configuration of log4j in the application war file. Will need to place log4j.xml in WEB-INF/classes and have a log4j.jar in WEB-INF/lib folder.


There will be one class loader instance for each application or standalone module. In other words, classes in app1.war will be loaded in different class loader than the classes in app2.war. This is the default behavior of any Java EE server; So it really doesn't matter about having classes with the same package/names and/or different content. This is the default behavior of any Java EE server.

Having said that, if you tweak the class loader policy of the server or try to load classes (reflect) using anything other than Thread.currentThread().getContextClassLoader(), you could be asking for trouble.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜