java 在 JBoss AS 5 中将共享库放在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2108975/
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
Where to put a shared library in JBoss AS 5?
提问by Tushar Khairnar
I m new to Jboss, but I have multiple web applications each using spring-hibernate and other open source libraries and portlets, so basically now each war file includes those jar files. How do I move these jars to a common location so that I don't have to put these in each war file? I guess location is server/default/lib, but I'm not sure.
我是 Jboss 的新手,但我有多个 Web 应用程序,每个应用程序都使用 spring-hibernate 和其他开源库和 portlet,所以现在基本上每个 war 文件都包含这些 jar 文件。我如何将这些 jars 移动到一个公共位置,这样我就不必将它们放在每个 war 文件中?我猜位置是server/default/lib,但我不确定。
Also, how is it different to have those jars at WEB-INF/libvs. JBOSS/server/default/lib? Will I face any classloader issue?
另外,将这些罐子放在WEB-INF/libvs上有什么不同JBOSS/server/default/lib?我会遇到任何类加载器问题吗?
Also I have static data stored in static fields like Singleton, will those be shared across all WAR files?
此外,我将静态数据存储在静态字段中,例如Singleton,这些数据会在所有 WAR 文件中共享吗?
回答by Ondra ?i?ka
Classloading:
类加载:
You're right, put the .jars to JBOSS/server/<configuration>/lib, or JBOSS/lib.
你是对的,把.jars放在JBOSS/server/<configuration>/lib, 或JBOSS/lib。
JBoss AS comes with bundled Hibernate libs which are tested with that AS version.
JBoss AS 附带捆绑的 Hibernate 库,这些库已用该 AS 版本进行了测试。
See jboss-6.0.0-SNAPSHOT\server\default\conf\jboss-service.xml:
见jboss-6.0.0-SNAPSHOT\server\default\conf\jboss-service.xml:
<server>
<!-- Load all jars from the JBOSS_HOME/server/<config>/lib directory and
the shared JBOSS_HOME/common/lib directory. This can be restricted to
specific jars by specifying them in the archives attribute.
TODO: Move this configuration elsewhere
-->
<classpath codebase="${jboss.server.lib.url}" archives="*"/>
<classpath codebase="${jboss.common.lib.url}" archives="*"/>
</server>
Also see:
另见:
- http://community.jboss.org/wiki/classloadingconfiguration
- http://community.jboss.org/wiki/JbossClassLoadingUseCases
- http://community.jboss.org/wiki/classloadingconfiguration
- http://community.jboss.org/wiki/JbossClassLoadingUseCases
Difference between WEB-INF/liband JBOSS/server/default/lib:
WEB-INF/lib和之间的区别JBOSS/server/default/lib:
Libs in WEB/libcome with your WAR and are only visible within that WAR.
If you have other module, e.g. EJB JAR, they will not be visible from it and you'll get ClassNotFoundExceptionor (if you have the class in multiple places) ClassCastException.
库WEB/lib随您的 WAR 一起出现,并且仅在该 WAR 中可见。如果您有其他模块,例如 EJB JAR,它们将不会从中可见,您将获得ClassNotFoundExceptionor(如果您在多个位置有该类)ClassCastException。
Libs in JBOSS-AS/server/<config>/libare visible for whole server, thus all deployed apps and their modules. However (IIRC) they don't have precedence, so if you bring that lib e.g. in a WAR, but not in EJB jar, you can end up using two different versions, which is undesirable (will likely lead to aforementioned ClassCastException).
Libs inJBOSS-AS/server/<config>/lib对整个服务器都是可见的,因此所有部署的应用程序及其模块。但是(IIRC)它们没有优先级,所以如果你在一个 WAR 中引入这个库,而不是在 EJB jar 中,你最终可能会使用两个不同的版本,这是不可取的(可能会导致前面提到的ClassCastException)。
Class loading behavior may be tweaked several ways, see e.g. JBoss wiki.
可以通过多种方式调整类加载行为,例如参见JBoss wiki。
Static data:
静态数据:
Don't rely on static fields in Java EE, that brings troubles. For instance,. the same class can be loaded by different classloaders, so there will be multiple instances of these static values.
If you want to share data amongst more WARs, use an external storage - a database, a file (with synchronization if you write to it), JBoss Cache, etc.
不要依赖 Java EE 中的静态字段,这会带来麻烦。例如,。同一个类可以被不同的类加载器加载,因此这些静态值会有多个实例。
如果您想在更多 WAR 之间共享数据,请使用外部存储 - 数据库、文件(如果写入则同步)、JBoss 缓存等。
回答by Vit
回答by Anshul Sood
- Go to %JBOSS_HOME%\server\default\conf directory
- Open file jboss-service.xml
Under tag you will find
- 进入 %JBOSS_HOME%\server\default\conf 目录
- 打开文件 jboss-service.xml
在标签下你会发现
Add a new classpath tag as below to include the sharedlib folder on your local machine
添加一个新的类路径标记,如下所示,以包含本地计算机上的 sharedlib 文件夹
Note: Please make sure to include file protocol to code base
注意:请确保在代码库中包含文件协议
回答by Gordon
JBOSS/server/default/lib works fine.
JBOSS/server/default/lib 工作正常。
All the jars in that folder will be loaded into JBoss.
该文件夹中的所有 jar 文件都将加载到 JBoss 中。

