在 JBoss AS7 独立部署中加载 3rd 方 JAR 的最佳实践? [英] Best Practice for loading 3rd party JARs in JBoss AS7 standalone deployment?

查看:18
本文介绍了在 JBoss AS7 独立部署中加载 3rd 方 JAR 的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 JBoss-as-7.0.x 独立部署中加载 3rd 方 JAR 的最佳实践是什么?

What is the best practice for loading 3rd party JARs in JBoss-as-7.0.x standalone deployment?

我试过了:

  1. 将每个 JAR 部署为具有自己的 module.xml 描述符的独立模块;
  2. 在 WAR 的 WEB-INF/lib 目录中部署 JAR;
  3. 以及跨多个 WAR 共享的任何 JAR 的 foo.ear/lib 目录.

上述方法 1. 的明显优势是在部署时减少了内存占用,而不是方法 2. 和方法 3.但是,维护似乎非常困难,因为 JAR 所具有的每个依赖项都需要在module.xml 对于大量的 3rd 方库似乎不太易于维护.

The obvious advantage to approach 1. above is the reduced memory footprint at deploy time over apprach 2. and approach 3. However it seems to be pretty arduous to maintain as each dependency that a JAR has needs to be explicitly defined in the module.xml which doesn't seem very maintainable with large numbers of 3rd party libraries.

推荐答案

对于部署私有的较小依赖项,请将它们保留在 WEB-INF/lib 中的 .战争,这就是它的目的.如果您使用的是 Maven,那么对于 <compile/> 中的任何内容都应该是自动且透明的.范围.

For smaller dependencies that're private to a deployment, keep 'em in WEB-INF/lib in your .war, that's what it's for. If you're using Maven that should be pretty much automatic and transparent for anything in the <compile/> scope.

对于大型、复杂的依赖项或将在多个应用之间共享的依赖项,请使用选项 (4):

For big, complex dependencies or dependencies that'll be shared between several apps, use option (4):

将每个逻辑库(如OpenJPA"或Log4J")部署为一个模块,包括其 api 和 impl jar 以及其他 AS7 模块尚未提供的任何依赖 JAR.如果已经有一个模块,请添加对它的依赖,而不是向您的模块添加 JAR.如果多个不同的库共享一些公共依赖项,请将它们拆分为模块并将它们添加为module.xml 中的模块依赖项.

Deploy each logical library (like "OpenJPA" or "Log4J") as a module, including its api and impl jars and any dependency JARs that aren't already provided by other AS7 modules. If there's already a module add a dependency on it rather than adding a JAR to your module. If several different libraries share some common dependencies, split them out into modules and add them as module dependencies in module.xml.

使用 jboss-deployment-structure.xml让您的部署 .war/.ear/任何声明对模块的依赖,如果它没有被自动检测和自动加载.

Use jboss-deployment-structure.xml to have your deployment .war / .ear / whatever declare a dependency on the module if it isn't autodetected and autoloaded.

我发现这是一种中到低难度的方法,效果很好.这比在部署中将所有内容转储到 WEB-INF/lib 中更麻烦,这是 Java EE 标准要做的事情.它加快了重新部署的速度,并通过减少类/版本冲突节省了大量部署/测试时间.

I find this to be a medium-to-low-hassle approach that works well. It's more hassle than dumping everything into WEB-INF/lib inside the deployment, which is the Java EE standard thing to do. It speeds redeploys and it saves lots of deploy/testing time by reducing class/version conflicts.

如果您愿意做一些工作,您可以使用 Maven 和 maven-dependency-plugin 来生成包含传递依赖项的模块.您可以在 我为 AS 7 中的 EclipseLink 集成编写的模块中看到一个例子.我尽可能自动创建 AS7 模块.

You can use Maven and the maven-dependency-plugin to produce modules with the transitive dependencies already included if you're willing to do a bit of work. You can see one example of that in a module I wrote for EclipseLink integration in AS 7. I automate the creation of AS7 modules whenever possible.

这篇关于在 JBoss AS7 独立部署中加载 3rd 方 JAR 的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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