JBoss: WAR file in EAR can't find JAR library on classpath

早过忘川 提交于 2019-11-29 03:07:15

问题


I am having a problem deploying an ear with bundled wars, jars, and configuration files (.properties files) on JBoss 4.3-eap. Here is my ear structure:

+app.ear   
  +lib  
    *.jar libraries that the war's use  
    +classes  
      *.properties and other configuration files 
  +META-INF  
    application.xml  
    jbos-app.xml  
  app.war  
  app2.war  
  appn.war  

I have the following in my jboss-app.xml :

<jboss-app>
  <jmx-name>app.startup.JbossStartUpServer:service=JbossStartUpService</jmx-name>
</jboss-app>    

My application.xml looks like this:

<application id="app_id">
  <display-name>App>/display-name>
  <description>TheApp>/description>
<!--  
  <module  id="core">
    <java>lib/core.jar</java>
  </module>

  <module id="tag">
    <java>lib/tag.jar</java>
  </module>
-->  
  <module id="app">
    <web>
      <web-uri>app.war</web-uri>
      <context-root>/</context-root>
    </web>
  </module> 

  <module id="app2">
    <web>
      <web-uri>app2.war</web-uri>
      <context-root>/app2</context-root>
    </web>
  </module> 

  <module id="appn">
    <web>
      <web-uri>appn.war</web-uri>
      <context-root>/appn</context-root>
    </web>
  </module>

  <security-role id="secRole">
    <description>users</description>
    <role-name id="appRoleName">users</role-name>
  </security-role>

  <library-directory>lib</library-directory>

</application>

Basically, upon deploying the ear, I run into an issue where one of my wars can't find a class in the core.jar file (java.lang.NoClassDefFoundError). I think this is due to the fact that the war is not finding this library, even though it is in the lib folder/classpath. If I try to uncomment the first two modules to add the first party libraries (core.jar and tag.jar), all of a sudden the properties files can no longer be found (they are located, for now, in lib/classes, so that, I hope anyway, they are picked up by the classloader. Ideally I'd like to put classes in its own directory and add it to the classpath separately, but for now I am just trying to make this work).

I have tried some other things, including manually adding core.jar to the war's manifest.mf file, changing UseJBossWebLoader to true in the jboss-service.xml file under the jboss-web.deployer, and various combinations of the above, to no success. I either lose the classes directory from the classpath (lib folder) and none of my properties files get picked up, or the war can't access the proper class from the jar. I think there must be some configuration that is wrong, and while I've tried reading up on the way JBoss does EAR deployments and classloading, I can't seem to adapt it to my current setup.

Any suggestions would be greatly appreciated.

Here are some sites that I have been looking at:
Raible Designs JBoss ClassLoader Logic

These are just a few of the sites I have looked at. The problems might stem from the setup of the project as well, as this is a large established project that is (to an extent) being migrated from a weblogic deployment to Jboss. So if there is anything that SHOULD work, but doesn't, it might be an issue with some of the code/project configuration. Unfortunately, I am not at the point yet where I can tell if its a JBoss related problem, or a problem with the project.


回答1:


The <library-directory> tag in application.xml is a JavaEE5 feature, and I don't think that JBoss 4.3 is fully JavaEE5-compliant (it can do EJB3, yes, but it's only partial support).

So you need to go back to using explicitly declared JAR files:

<module>
    <java>lib/core.jar</java>
</module>

As for your properties files, you need to add the directory that they're in as a java module, so for your example:

<module>
    <java>lib/classes</java>
</module>


来源:https://stackoverflow.com/questions/1330067/jboss-war-file-in-ear-cant-find-jar-library-on-classpath

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