Add the same jars to all your war without including in your packaging them thanks to TomEE

In some case you will want to add a set of jars to all webapps deployed to TomEE.

You can imagine a lot of ways to do so but in fact TomEE includes a simple solution to manage it.

The first step is to create a folder with all needed jars. Let call it additional-lib.

A common use case can be to add hibernate jars. Put them all in this folder then add the configuration of the next steps in your ${home}/.openejb/  and all your TomEE will be able to use Hibernate out of the box. Another use case is to add common jdbc drivers, custom server event listeners…

Once you got your folder with the libraries to add simply configure the service org.apache.openejb.assembler.classic.enricher.AdditionalLibClassLoaderEnricherObserver. It has a single parameter path you should configure to be the folder you prepared:

enricher = new://Service?class-name=org.apache.openejb.assembler.classic.enricher.AdditionalLibClassLoaderEnricherObserver
# by default additional-lib is taken in <tomee> installation
enricher.path = /home/foo/additional-lib

Then simply deploy your webapp without the jar from additional-lib and your webapp will be able to use the classes/resources contained in the jars of this folder :).

If you don’t like the properties style use tomee.xml:

<Service id="enricher" class-name="org.apache.openejb.assembler.classic.enricher.AdditionalLibClassLoaderEnricherObserver">
  path = /home/foo/additional-lib

You can define several enrichers (just change the id). So for instance one for hibernate, one for deltaspike etc…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s