aspose file tools
The moose likes Websphere and the fly likes WebSphere J2EE Module Dependencies Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Products » Websphere
Reply Bookmark "WebSphere J2EE Module Dependencies" Watch "WebSphere J2EE Module Dependencies" New topic
Author

WebSphere J2EE Module Dependencies

Pat Short
Greenhorn

Joined: Mar 21, 2008
Posts: 22
I have an EAR file which contains 4 webapps. The jars used by each webapp reside at the EAR level. Now each webapp references these jars as J2EE modules under Properties>J2EE Module Dependencies>J2EE Modules. This causes a problem in my application which uses spring. Each webapp seems to use the same spring context which cause problems when beans with the same name are created by each webapp. Is this the correct behavior? When you reference jars as J2EE Modules does it lead to a share context across all web apps?

Thanks in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This problem could be caused by using a Singleton Spring bean factory. Because all of your web applications share the same JVM, they'll also share the same bean factory. I'd suggest you switch to a bean factory stored in the ServletContext object. That way you're sure to have a separate one for each web application.

Another possibility would be to configure WAS such that each web application has its own ClassLoader.


Merrill
Consultant, Sima Solutions
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

Ah....WebSphere classloading issues... I have a little tutorial on the topic that you might find useful:

WebSphere Classloading - Understanding how classes get loaded onto the JVM in WebSphere

Indeed, with all of the war files pulling from common jar files in the root of the ear, they will all be accessing the Spring resources through the same classloader.

These are the WebSphere classloaders:


Everything is probably being loaded by the common CompoundClassLoader, which is causing the problems.

Using the ServletContext is a good idea. What if you package the Spring components in the lib directory of the war files? Alternatively, you might want to switch around the PARENT_FIRST and PARENT_LAST settings on the web module.

Good luck! Classloader issues are always a pain.

-Cameron McKenzie


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Pat Short
Greenhorn

Joined: Mar 21, 2008
Posts: 22
Thanks for the quick response everyone. Each web app in the EAR is configured to have its own classloader. This option is selected under Enterprise Applications>MYEAR>Class loader. Also, the spring context is tied to the servletcontext as suggested below.

I've found a solution to the problem in the way I reference my jars in each web application. In my original thread, I posted that each webapp references these EAR level jars as J2EE modules under Properties>J2EE Module Dependencies>J2EE Modules in RAD. However, if I reference the jars as "Web Libraries" instead of "J2EE Modules" under the same configuraton option in my RAD environment, the problem does not occur. By changing this configuration option, each webapp get a copy of the jar files in their WEB-INF/lib directory. This solves my problems.

Therefore, this suggests if you want to share context among web apps in an EAR file, reference the EAR level jars as J2EE Modules. However, if each web needs its own copy, then reference the jars as Web Libraries. Hope this makes sense. Let me know if there's anything strange with this configuration.

Thanks
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

No problems with this at all. This is exactly how it should be done!

-Cameron McKenzie
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: WebSphere J2EE Module Dependencies
 
Similar Threads
WSAD Build Path vs. DD vs. Class Path
Best practices for setting up modules with interdependencies in CVS
Sharing information across WAR applications
Application.xml Module loading order
Loading sequence of the different modules in an EAR....?