JBoss AS 5 中的共享库应该放在哪里?
我是 Jboss 新手,但我有多个 Web 应用程序,每个应用程序都使用 spring-hibernate 和其他开源库和 portlet,所以基本上现在每个 war 文件都包含这些 jar 文件。如何将这些 jar 移动到一个公共位置,以便不必将它们放入每个 war 文件中?我猜位置是server/default/lib
,但我不确定。
另外,将这些 jar 放在 WEB-INF/lib
与 JBOSS/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
类加载:
你是对的,将
.jar
放入JBOSS/server//lib
或JBOSS /lib
.JBoss AS 附带捆绑的 Hibernate 库,这些库已使用该 AS 版本进行了测试。
请参阅
jboss-6.0.0-SNAPSHOT\server\default\conf\jboss-service.xml
:另请参阅:
WEB-INF/lib
和JBOSS/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
.jar
s toJBOSS/server/<configuration>/lib
, orJBOSS/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
:Also see:
Difference between
WEB-INF/lib
andJBOSS/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 aforementionedClassCastException
).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.
http://www.mastertheboss.com/ en/jboss-server/211-configuring-jboss-shared-libs.html
http://www.mastertheboss.com/en/jboss-server/211-configuring-jboss-shared-libs.html
JBOSS/server/default/lib 工作正常。
该文件夹中的所有 jar 都将加载到 JBoss 中。
JBOSS/server/default/lib works fine.
All the jars in that folder will be loaded into JBoss.
在标签下您将找到
添加如下新的类路径标记以包含本地计算机上的共享库文件夹
注意:请确保将文件协议包含到代码库中
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