Search code examples
javamavenjarmaven-2classloader

How use two verions of itext jar files in pom.xml?


In my project i have dependencies displaytag and birt-runtime. And here display tag needs itext-2.0.1.jar and birt-runtime needs itext-2.1.7.jar so how can i declare this in my pom.xml to use itext-2.0.1.jar only by displaytag and use itext-2.1.7.jar only by birt-runtime. could some one let me know how to achieve this? Thanks in advance.


Solution

  • In normal java application this is not possible, because in the application itext 2.1 and 2.0 will share the same classloader. But normally, java-apis take care about backward-compatibility, so it should be possible to include only 2.1.

    If not, you need multiple classloaders and then it will become complicated.

    Existing solutions:

    • You could try to add an OSGi container to your application and run both dependencies as a separate osgi-bundle.
    • If you run a jboss application server, you could create one module with displaytag and another one with birt-runtime.

    DIY:

    • I've never done this but you could try to create to manage your own classloaders in your application and load the dependent jars into each own classloader. This article seems to cover the topic.