Java JBoss:EAR 中的 WAR 文件在类路径上找不到 JAR 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1330067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JBoss: WAR file in EAR can't find JAR library on classpath
提问by Mike
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:
我在 JBoss 4.3-eap 上部署带有捆绑战争、jar 和配置文件(.properties 文件)的耳朵时遇到问题。这是我的耳朵结构:
+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.xml 中有以下内容:
<jboss-app>
<jmx-name>app.startup.JbossStartUpServer:service=JbossStartUpService</jmx-name>
</jboss-app>
My application.xml looks like this:
我的 application.xml 看起来像这样:
<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.NoClassDefFoundErro
r). 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).
基本上,在部署耳朵时,我遇到了一个问题,即我的一个战争在core.jar
文件 ( java.lang.NoClassDefFoundErro
r) 中找不到类。我认为这是由于战争没有找到这个库,即使它在lib
文件夹/类路径中。如果我尝试取消注释前两个模块以添加第一方库(core.jar
和tag.jar
),突然之间无法再找到属性文件(它们现在位于 中lib/classes
,因此,无论如何,我希望它们是由类加载器拾取。理想情况下,我想将类放在它自己的目录中并将其单独添加到类路径中,但现在我只是想完成这项工作)。
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.
我曾尝试一些其他的东西,包括手动添加core.jar
到战争的manifest.mf
文件,改变UseJBossWebLoader
真中jboss-service.xml
下的文件jboss-web.deployer
,以及上述的各种组合,没有成功。我要么丢失了classes
类路径(lib
文件夹)中的目录并且我的属性文件都没有被拾取,要么战争无法从 jar 访问正确的类。我认为一定有一些配置是错误的,虽然我已经尝试阅读 JBoss 执行 EAR 部署和类加载的方式,但我似乎无法适应我当前的设置。
Any suggestions would be greatly appreciated.
任何建议将不胜感激。
Here are some sites that I have been looking at:
Raible Designs JBoss ClassLoader Logic
以下是我一直在查看的一些网站:
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.
这些只是我看过的一些网站。问题也可能源于项目的设置,因为这是一个大型既定项目,正在(在某种程度上)从 weblogic 部署迁移到 Jboss。因此,如果有任何应该工作但不工作的内容,则可能是某些代码/项目配置的问题。不幸的是,我还没有到可以判断是 JBoss 相关问题还是项目问题的地步。
采纳答案by skaffman
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).
该<library-directory>
标签中application.xml
是JavaEE5的功能,我不认为JBoss的4.3是完全JavaEE5兼容的(它可以做EJB3,是的,但它只是部分支持)。
So you need to go back to using explicitly declared JAR files:
所以你需要回到使用显式声明的 JAR 文件:
<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:
至于您的属性文件,您需要将它们所在的目录添加为 java 模块,因此对于您的示例:
<module>
<java>lib/classes</java>
</module>