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

孤人 提交于 2019-12-05 08:20:00

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.

Peter Lawrey

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

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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!