0

I am converting a regular J2EE application to use Maven. I was able to successfully convert to Maven and I am getting successful "mvn deploy". The issue is facing after deploying the ear to WAS. I am getting SRVE0203E :Servlet [action] org.apache.struts.action.ActionServlet is missing another required class.

I had similar problems for different application and after trying couple of "exclusion" of jars I was able to deploy the application successfully in WAS. I have following question.

  1. How can we identify what all jars needs to be present in WEB-inf\lib folder?

  2. How can we determine, what all jars needs to be present in the .class-path of wars meta-inf.

  3. How can we determine that the war will work even if the jar is mentioned in .classpath but not mandatory that it needs to be present in web-inf\lib (ie classloader will pull from ear instead of war)

FYI I am using j2ee 1.4

techrawther
  • 163
  • 3
  • 15

1 Answers1

2

A Java EE application executing in a Container has a classpath composed of several levels:

  1. Web application classpath, represented by the JAR and Class files included in WEB-INF/lib
  2. Enterprise application classpath, that includes JAR files declared at EAR level
  3. Container classpath, that contains the Websphere Runtime and Shared Libraries

There are complex dependency rules between these levels, but the main idea is that all your application libraries must be included between this levels avoiding any conflict that can corrupt the classpath.

With that in mind, a simplistic approach would be to put all your application JAR's in WEB-INF/lib. That would work but if your EAR has two Web Modules each Module would require it own set of JARS. A more robust approach would be to include common JARs at EAR level so JAR duplicity would be avoided.

If the case is that your company has a propietary framework that all applications use, it would be silly to include the same JARS in every EAR application of the company. A better way to do this would be to configure the company framework as a shared library in the Container so it can be reused by all the applications.

In conclusion, there are several factors that determine your Java EE application classpath. You should keep in mind to always avoid duplicity and version conflict, so your app can resolve it dependencies smoothly.

Carlos Gavidia-Calderon
  • 7,145
  • 9
  • 34
  • 59
  • Hi Carlos Thanks alot for your suggestion. This is what I am running in to. 1. If I am right then duplicating jars in both ear and war can cause class loading issue. 2. For eg If I am using some jars like struts.jar in my web-inf lib what is the best way to avoid duplicacity in both ear and war, because struts may bring in some additional transitive dependent jars.So if we exclude the other transitive dependency it fails after deploying saying required class was not available while invoking the struts. I am still having the issue and I dont know how to resolve this. – techrawther Mar 13 '12 at 01:35
  • How many Web module does your Enterprise Application have? If it has only one module, maybe the best way to is to put Struts and all it dependencies inside WEB-INF lib, so it doesn't mess with the classpath of the other modules – Carlos Gavidia-Calderon Mar 13 '12 at 02:13
  • I have 3 web modules and copying all the jars to all the 3 war files will be space consuming. – techrawther Mar 15 '12 at 01:26
  • A strategy for using a shared space within the ear is known as creating skinny wars. http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html – Nick Aug 20 '12 at 18:38