JBoss-战争图书馆依赖 [英] JBoss - War library dependencies
问题描述
我正在尝试添加一些依赖项jar文件.但是,这些文件放在lib/endorsed
或WEB_INF/lib.jar
中时,会导致jboss实例启动错误.我想这是因为JBoss的扁平类加载器结构而发生的.如果有人在jboss-web.xml
I am trying to add some dependencies jar files. But these files when put in lib/endorsed
or in WEB_INF/lib.jar
results in startup error for jboss instances. I suppose this is happening because flat classloader structure of JBoss. If somebody has implemented the classloader settings in jboss-web.xml
<class-loading>
<loader-repository>com.example:archive=unique-archive-name</loader-repository>
</class-loading>
有人可以给我一个真实的例子吗?
Can somebody give me a real life example ?
我还应该将这些jar文件-jboss的lib/endorsed
或lib
文件夹放置在deploy文件夹或WEB_INF/lib
Also where should I place these jar files - lib/endorsed
of jboss, or lib
folder in deploy folder or in WEB_INF/lib
推荐答案
达菲(Duffymo)关于不将罐子放入 认可的 的指令会被忽略.
Duffymo's directive on not putting jars in endorsed is ignored at your peril.
更多详细信息:
将库放置在 WEB-INF/lib 中是可移植性和一致性的最佳实践,因为它遵循创建自给自足和可分发的Web存档的标准规定,但是您需要支付一定的费用注意您要放入 jboss-web.xml 中的 class-loading 声明.
Placing libraries in your WEB-INF/lib is a best practice for portability and consistency as it adheres to a standard provision for creating self-sufficient and distributable web archives, but you need to pay close attention to the class-loading declaration you're putting in your jboss-web.xml.
假设一个简单的场景没有 类加载声明和一个虚构的 example.jar :
Assume a simple scenario without the class-loading declaration and a fictional example.jar:
- 如果将 example.jar 放在 WEB-INF/lib 中,并且会 不 也存在于 jboss//lib 中,那么 example.jar 仅对特定的WAR可见.
- 如果将 example.jar 放置在 WEB-INF/lib 中,并且 也存在于 jboss//lib 中, WEB-INF/lib 中的实例将被忽略,并且WAR将使用JBoss服务器实例的统一类加载器来从 jboss//lib/example.jar 加载示例类. (假设没有覆盖 class-loading 的情况下,同一服务器实例中的所有其他WAR或EAR也一样.)
- If you place example.jar in WEB-INF/lib and it does not also exist in jboss//lib, then example.jar will only be visible to that specific WAR.
- If you place example.jar in WEB-INF/lib and it does also exist in jboss//lib, the instance in WEB-INF/lib will essentially be ignored and the WAR will use the JBoss server instance's unified class loader to load the example classes from jboss//lib/example.jar. (The same would apply to any other WARs or EARs in the same server instance, assuming no class-loading overrides.)
类加载声明在(例如)您具有两个不同版本的 example.jar 的情况下是必需的: -jboss//lib:example1.0.jar -WEB-INF/lib:example2.0.jar
The class-loading declaration is necessary in cases (such as) where you have two different versions of example.jar: - jboss//lib: example1.0.jar - WEB-INF/lib: example2.0.jar
在这种情况下,JBoss将为您的WAR创建一个唯一的隔离类加载器,这将避免 jboss//lib/example1.0.jar ,而推荐使用 WEB-INF/lib/您的WAR上下文中的example2.0.jar .
In this case, JBoss will create a unique and isolated classloader for your WAR which will avoid jboss//lib/example1.0.jar in favour of WEB-INF/lib/example2.0.jar in the context of your WAR.
总而言之,如果您仅在jboss服务器实例中运行一个WAR和/或没有冲突的JAR问题,请放弃 class-loading 声明,并将您的JAR放在 jboss//lib .它使WAR文件更轻便,整体部署 可能会更简单,并且在热部署期间您不会因为额外的类版本而占用额外的内存.
In summary, if you're only running one WAR in the jboss server instance and/or you have no conflicting JAR issues, ditch the class-loading declaration and put your JARs in jboss//lib. It makes the WAR file more lightweight, overall deployment may be simpler and you will not consume additional memory with extra class versions during hot-deploys.
这篇关于JBoss-战争图书馆依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!