Neo4j中的lucene-core-3.6.2与我当前项目中的lucene-core-4.3.1冲突

Neo4j中的lucene-core-3.6.2与我当前项目中的lucene-core-4.3.1冲突,lucene,neo4j,dependencies,Lucene,Neo4j,Dependencies,我正在我的项目中使用Lucene 4.x.,该项目需要Lucene-core-4.3.1。最近,我开始探索Neo4j数据库来维护我的数据图表lucene-core-3.6.2jar与neo4j-community-2.1.4捆绑在一起,当我将这两个jar添加到我的项目中时,我得到了一个例外 Severe: Exception while loading the app Severe: Undeployment failed for context /ibet Info: file

我正在我的项目中使用
Lucene 4.x.
,该项目需要
Lucene-core-4.3.1
。最近,我开始探索Neo4j数据库来维护我的数据图表
lucene-core-3.6.2
jar与
neo4j-community-2.1.4
捆绑在一起,当我将这两个jar添加到我的项目中时,我得到了一个例外

Severe:   Exception while loading the app
Severe:   Undeployment failed for context /ibet
Info:     file:/home/caleb/NetBeansProjects/qualebs/build/web/WEB-INF/classes/_ibetPU logout successful
Severe:   Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoSuchFieldError: LUCENE_43
在我的代码中引发此异常的第一个位置是

private static final StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_43);
以及我尝试调用
Version.LUCENE_43

我正在使用netbeans进行开发,根据上的说明,我需要复制所有JAR或将它们从netbeans添加到我的项目中。JDK8,JavaEE7Glassfish4.0。我所做的所有研究,包括并导致我得出结论,在同一个JVM中使用两个版本的JAR并不简单。我唯一的选择是使用lucene 3.x及以下版本而不是4.x,或者干脆推迟为我的项目实现graph数据库,直到neo4j与lucene core的未来版本兼容。所以我问这些是否真的是唯一的选择?我如何使用这两个JAR而不运行两个JVM或为每个JVM使用类加载器

同时,我尝试从我的项目中排除
lucene-core-3.6.2
,然后在我的
ContextListener
类中尝试下面的代码来加载类
org.apache.lucene.document.Fieldable
——这是引发NoClassDefFoundError的类

 @Override
public void contextInitialized(ServletContextEvent sce) {
    final ServletContext context = sce.getServletContext();
    try {
        URL[] urls;
        URL url = new URL("file://" + context.getRealPath("/"));
        URI resolve = url.toURI().resolve("../../../" + "jars/neo4j-community-2.1.4/lucene-core-3.6.2.jar");
        urls = new URL[]{resolve.toURL()};
        URLClassLoader loader = URLClassLoader.newInstance(urls);
        loader.loadClass("org.apache.lucene.document.Fieldable");

    } catch (MalformedURLException | URISyntaxException | ClassNotFoundException ex) {
        Logger.getLogger(ContextListener.class.getName()).log(Level.SEVERE, null, ex);
    }
    Neo4JDAO.createGraphDbConnection(context.getRealPath("/") + "/graph/");        
}
但我还是有个例外。我很困惑如何加载这个类,使它可以从任何地方访问,而不仅仅是在ContextListener的ContextInitialized方法中

Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /home/caleb/NetBeansProjects/qualebs/build/web/graph

Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.extension.KernelExtensions@1d202bd' failed to initialize. Please see attached cause exception.
    at
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.document.Fieldable
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1761)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1611)
    ... 61 more

如果您想在嵌入式模式下使用Neo4j,我认为如果不使用适当的类加载器分离,就没有办法做到这一点


您是否考虑过在服务器模式下使用Neo4j,并依赖您的应用程序使用(或)与数据库通信?这样,您就可以在应用程序中自由选择和依赖应用程序。

嗨,Stefan,感谢您的快速响应。在考虑了您的建议之后,我想我将使用JDBC驱动程序。我也试图用UrlClassLoader解决同样的问题,但我似乎无法让它工作。我已经审阅并添加了代码。你能帮我理解我哪里出了问题吗。先谢谢你。