26

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.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
travega
  • 8,284
  • 16
  • 63
  • 91
  • I am trying to migrate to JBoss7 and kept getting Class Path Entry error, eg. "does not point to a valid jar for a Class-Path reference" - seems like you solved / didnt encounter such error. This probably have something to do with JBoss7 Class loading, quite a few people got the same problem as me but no solution - do you have any idea? – TS- Dec 02 '11 at 19:57
  • Is sounds like your problem is either in your module.xml file (if you are loading your JARs as modules) or your jboss-deploment-structure.xml file. The best way to reference you static library JARs is to put them in a sub directory of the modules directory. If you are trying to reference the "org.foo.bar.FooBar;" class in your FooBarJar.jar file then your directory structure wants to be "JBOSS_HOME/modules/org/foo/bar/main/FooBarJar.jar" and you will need to include your "JBOSS_HOME/modules/org/foo/bar/main/modle.xml" file to define the mapping to the jar and to any dependencies it may have... – travega Dec 08 '11 at 02:36
  • 1
    ...(contd.) Your module.xml file will look like: " ". You can then add your module reference to your jboss-deploment-structure.xml file which sits in your WAR's WEB-INF directory. This will look some thing like: ""... – travega Dec 08 '11 at 02:41
  • Deploying each jar as a module sound like a disaster waiting to happen. :) – ziggy Feb 04 '12 at 18:49

1 Answers1

16

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.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • In a cluster (domain) environment, can you package your module in a .war or other container and deploy it to all the slaves from the domain-controller? Or, do you manually copy the modules into each slavedirectory/modules/...? – Gregor Jan 28 '15 at 15:31
  • @Gregor I haven't used the cluster mode, so I don't know. I suspect you probably have to copy manually, but it's been a couple of years since since I did anything with JBoss AS and Java EE (thankfully). Sorry I can't help. Try posting a new question and linking back to this one for context. – Craig Ringer Jan 31 '15 at 22:51
  • @Gregor did you find workaround for domain mode. My domain does not load module on restart also – Aadam Sep 24 '16 at 05:31