Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

Best Practice for loading 3rd party JARs in JBoss AS7 standalone deployment?

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

I have tried:

  1. deploying each JAR as an independent module with it's own module.xml desriptor;
  2. deploying the JARs in the WEB-INF/lib directory of a WAR;
  3. and the foo.ear/lib directory for any JARs shared across multiple WARs.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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.

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...