Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java: use two version of the same lib in one webapp

I'm facing the following problem: I have one module in my webapp that needs jaxb 1.x and the other module needs jaxb 2.x. The first module doesn't work with the new version of jaxb, and the opposite. How can I use these two jars in one project? Thanks.

like image 908
Nick Avatar asked Aug 30 '11 08:08

Nick


3 Answers

For a regular application, usually very different versions use different package names. If this is the case, you can use them both at once without problem. However if they are the same, you can use jarjar to rename the package.

However since you are using a web container each application should use the version you deploy and not the other version. i.e. the web container works it out for you.

OSGi is another container which manages the versions much more explicitly and give you more control over these issues (however I believe you need it just for this)

like image 122
Peter Lawrey Avatar answered Nov 09 '22 16:11

Peter Lawrey


You have got a jar-hell issue. Generally speaking in normal java environment it's impossible to solve this problem. You have to force modularization into your project by using OSGI. Starting point: http://www.osgi.org/About/HowOSGi

like image 2
Illarion Kovalchuk Avatar answered Nov 09 '22 17:11

Illarion Kovalchuk


If you are using the JAXB reference implementation, then you can use your JAXB 1 models with the JAXB 2 runtime by including the jaxb1-impl.jar.

  • http://jaxb.java.net/faq/index.html#running1Apps
like image 1
bdoughan Avatar answered Nov 09 '22 18:11

bdoughan