开发者

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

开发者 https://www.devze.com 2023-03-31 21:30 出处:网络
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,

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.


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)


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


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


As Shaman said is imposible to resolve this issue.

Let's see: the servlet container JRE has only one classloader, and this classloader can load and use one class from jaxb or the other, but not both that will give you a classdefnotfound exception or something similar.

You can not solve this directly: you can get the code (is opensource) and change the package of one to another name so the classloader can use both. I do not recommend you this solution, is a bad one.

Better is that you migrate the code to use the most modern API (jaxb 2)

0

精彩评论

暂无评论...
验证码 换一张
取 消