使用不同版本的相同库
我有 2 个库:owls.jar 和 envy.jar。它们依赖于 lib jena.jar,但是两个不同的、不兼容的版本。 envy 使用旧版本 - jena.jar,owls 新版本 - jena2.jar 我想在 glassfish-3.0.1 上运行的 Web 应用程序中一起使用它们。我正在使用 IDEA 11 来部署我的网络应用程序。
我有这样的目录树:
- webapp/web-inf/lib/envy.jar
- webapp/web-inf/lib/owls.jar
- webapp/lib/envy/jena.jar
- webapp/lib/owls/jena2.jar
我添加到envy 和 owls libs 类路径的 manifest.mf 如下所示:../../lib/envy/jena.jar
我使用 -verbose:class 选项,并且总是从 jena.jar 加载类。如果我使用或不使用 无论如何,我总是从 jena.jar 加载类。仅当我删除 envy.jar 时,才会从 jena2.jar 加载类
有没有办法使用这两个库?
I have 2 libs: owls.jar and envy.jar. They depends on lib jena.jar but two differnet, incompitables versions. envy using old version - jena.jar, owls new - jena2.jar
I want to use them togever at web application running on glassfish-3.0.1. I`m using IDEA 11 for deploying my web app.
I have directory tree like this:
- webapp/web-inf/lib/envy.jar
- webapp/web-inf/lib/owls.jar
- webapp/lib/envy/jena.jar
- webapp/lib/owls/jena2.jar
I add into manifest.mf of envy and owls libs class-path like this: ../../lib/envy/jena.jar
I use -verbose:class option and I always get loaded class from jena.jar.If I`m using or not using envy.jar at all, I always get loaded class from jena.jar. Only if I delete envy.jar then classes loads from jena2.jar
Is there are any way to use both of this libs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用同一类的两个不同版本的唯一方法是通过两个不同的类加载器来加载它们。也就是说,您必须使用一个类加载器加载 owls.jar__ 和 __jena.jar ,并使用另一个类加载器加载 envy.jar 和 jena2.jar 。这个解决方案有它自己的陷阱,您可能应该正确定制代码,以便在必要时能够使用另一个类加载器,也许您最终会编写自己的类加载器。
据我所知,对于这种情况没有内置的解决方案。也许,使用上面的 jar 的旧版本可以支持相同版本的 jena.jar 更容易,这是更简单的解决方案。
The only way to use 2 different version of the same class is to laod them through 2 different classloaders. That is you have to load owls.jar__and __jena.jar with one class loader and envy.jar and jena2.jar with another. This solution has its own pitfalls, you should probably right custom code that will be able to use another classloader when it's necessary, maybe you will end up with writing your own class loader.
As far as I know there is no built in solution for such situation. May be, it is easier to use older version of one the jar's above that can support the same version of jena.jar This is much easier solution.