How to use two versions of jar in my java project

孤街醉人 提交于 2019-11-27 16:36:40

问题


In my java project, I need to use neo4j-1.9.3 that depends on lucene-3.6.2, and ElasticSearch which depends on lucene-4.4.0. I know that if I want to use two versions of lucene directly, I can use ClassLoader to load different classes from the lucenes.

But the problem is that I won't use lucene's apis directly now. Is there any way that lucene-3.6.2 can be loaded when neo4j's apis are running, and lucene-4.4.0 can be loaded while running elasticsearch's apis. The two versions of lucene conflict now, and I need to run neo4j and elasticsearch in one project. How could I solve the dependency problem?

Thanks in advance.


回答1:


You could still use a ClassLoader solution, but that is a nasty business where it is easy to make mistakes.

You could also use different JVM's.

But the solution I would personally choose is either (or both) of the following:

  • Verify that Neo4J breaks with Lucene 4.x. Maybe you will get lucky and there won't be any problems using the latest version.
  • Split them up into two applications where one of them, say Neo4J, is accessed by the other application via web service (most likely REST) calls. Neo4J has a built-in REST API anyway.



回答2:


OSGi can fix this problem. An OSGi bundle is nothing more than a jar with additional metadata detailing versions. A bundle has a version number, and will detail version numbers (or ranges) of dependent jars.



来源:https://stackoverflow.com/questions/19395004/how-to-use-two-versions-of-jar-in-my-java-project

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