JBoss AS 5 中的共享库应该放在哪里?

发布于 2024-08-19 05:06:39 字数 371 浏览 4 评论 0原文

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

另外,将这些 jar 放在 WEB-INF/libJBOSS/server/default/lib 有何不同?我会遇到任何类加载器问题吗?

另外,我将静态数据存储在静态字段(例如 Singleton)中,这些数据会在所有 WAR 文件之间共享吗?

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.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不甘平庸 2024-08-26 05:06:39

类加载:

你是对的,将 .jar 放入 JBOSS/server//libJBOSS /lib.

JBoss AS 附带捆绑的 Hibernate 库,这些库已使用该 AS 版本进行了测试。

请参阅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>

另请参阅:

WEB-INF/libJBOSS/server/default/lib 之间的区别:WEB/lib 中的Lib

与您的 WAR 一起提供,并且仅在该 WAR 中可见。
如果您有其他模块,例如 EJB JAR,它们将不会从中可见,并且您将得到 ClassNotFoundException 或(如果您在多个位置都有该类)ClassCastException

JBOSS-AS/server//lib 中的库对于整个服务器可见,因此所有已部署的应用程序及其模块都是可见的。但是(IIRC)它们没有优先级,因此如果您将该库引入 WAR 中,而不是 EJB jar 中,则最终可能会使用两个不同的版本,这是不可取的(可能会导致前面提到的 ClassCastException )。

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

静态数据:

不要依赖Java EE中的静态字段,这会带来麻烦。例如,。同一个类可以被不同的类加载器加载,因此这些静态值会有多个实例。
如果您想在多个 WAR 之间共享数据,请使用外部存储 - 数据库、文件(如果写入则需要同步)、JBoss Cache 等。

Classloading:

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

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

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>

Also see:

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

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 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).

Class loading behavior may be tweaked several ways, see e.g. 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.

ゞ花落谁相伴 2024-08-26 05:06:39

JBOSS/server/default/lib 工作正常。

该文件夹中的所有 jar 都将加载到 JBoss 中。

JBOSS/server/default/lib works fine.

All the jars in that folder will be loaded into JBoss.

黒涩兲箜 2024-08-26 05:06:39
  1. 转到 %JBOSS_HOME%\server\default\conf 目录
  2. 打开文件 jboss-service.xml
  3. 在标签下您将找到

添加如下新的类路径标记以包含本地计算机上的共享库文件夹

注意:请确保将文件协议包含到代码库中

  1. Go to %JBOSS_HOME%\server\default\conf directory
  2. Open file jboss-service.xml
  3. Under tag you will find

Add a new classpath tag as below to include the sharedlib folder on your local machine

Note: Please make sure to include file protocol to code base

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文