在JBoss AS 5中放置共享库的位置? [英] Where to put a shared library in JBoss AS 5?

查看:131
本文介绍了在JBoss AS 5中放置共享库的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Jboss的新手,但我有多个web应用程序,每个都使用spring-hibernate和其他开源库和portlet,所以基本上现在每个war文件都包含那些jar文件。如何将这些罐子移动到一个公共位置,这样我就不必将它们放在每个war文件中?我猜位置是 server / default / lib ,但我不确定。

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.

另外,它是怎么回事那些罐子在 WEB-INF / lib JBOSS / server / default / lib 不同?我会遇到任何类加载器问题吗?

Also, how is it different to have those jars at WEB-INF/lib vs. JBOSS/server/default/lib? Will I face any classloader issue?

此外,我还有静态数据存储在静态字段中,如 Singleton ,那些是在所有WAR文件中共享?

Also I have static data stored in static fields like Singleton, will those be shared across all WAR files?

推荐答案

分类加载:

你是对的,将 .jar 添加到 JBOSS / server /< configuration> / lib ,或 JBOSS / lib

You're right, put the .jars to JBOSS/server/<configuration>/lib, or JBOSS/lib.

JBoss AS带有捆绑的Hibernate库,它们使用该AS版本进行测试。

JBoss AS comes with bundled Hibernate libs which are tested with that AS version.

参见 jboss-6.0.0-SNAPSHOT \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ c>:

See 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>

另见:

  • http://community.jboss.org/wiki/classloadingconfiguration
  • http://community.jboss.org/wiki/JbossClassLoadingUseCases

WEB-INF / lib 与<$ c $之间的差异c> JBOSS / server / default / lib

Difference between WEB-INF/lib and JBOSS/server/default/lib:

WEB / lib中的Libs 带有你的WAR并且仅在该WAR中可见。
如果您有其他模块,例如EJB JAR,它们将不会显示它们,您将获得 ClassNotFoundException 或(如果您在多个位置有类) ClassCastException

Libs in WEB/lib come 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 ClassNotFoundException or (if you have the class in multiple places) ClassCastException.

中的Libs JBOSS-AS / server /< config> / lib 可见整个服务器,因此所有部署的应用程序及其模块。但是(IIRC)它们没有优先权,所以如果你带上那个lib,例如在WAR中,但在EJB jar中,你最终可能会使用两个不同的版本,这是不可取的(可能导致前面提到的 ClassCastException )。

Libs in JBOSS-AS/server/<config>/lib are 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).

类加载行为可以通过多种方式进行调整,参见例如 JBoss wiki

Class loading behavior may be tweaked several ways, see e.g. JBoss wiki.

静态数据:

不要依赖Java EE中的静态字段,这会带来麻烦。例如,。同一个类可以由不同的类加载器加载,因此这些静态值将有多个实例。

如果要在更多WAR之间共享数据,请使用外部存储 - 数据库,文件(带有如果你写它同步),JBoss Cache等。

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.

这篇关于在JBoss AS 5中放置共享库的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆