Which jars needs to be present in WEB-INF\lib and in .classpath

假如想象 提交于 2019-12-25 08:07:17

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/9560943/which-jars-needs-to-be-present-in-web-inf-lib-and-in-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!