.jar 冲突导致 java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase 异常
.jar conflict causes java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase exception
由于不同 .jar 文件中的不同 class 版本,我得到了这个异常:
java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, E:\neo4j
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:333)
at org.neo4j.kernel.EmbeddedGraphDatabase.(EmbeddedGraphDatabase.java:63)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:92)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
at neo4j_lucene.conflict_solver.ConfilctSolver.createDb(ConfilctSolver.java:55)
at neo4j_lucene.conflict_solver.ConfilctSolver.main(ConfilctSolver.java:35)
尽管我使用 ClassLoader
来解决这个问题,但我还是遇到了同样的异常。这是我的代码:
try {
CustomClassLoader ccl = new CustomClassLoader();
Object object;
Class clas;
clas = ccl
.loadClass("org.neo4j.graphdb.factory.GraphDatabaseFactory");
object = clas.newInstance();
graphDb = ((GraphDatabaseFactory) object)
.newEmbeddedDatabase(DB_PATH);
} catch (Exception e) {
e.printStackTrace();
}
自定义class加载程序代码:
public class CustomClassLoader extends ClassLoader {
private String jarFile = "C:/Users/RaufA/Desktop/test.jar"; // Path
// to
// the
// jar
// file
private Hashtable classes = new Hashtable(); // used to cache already
// defined classes
public CustomClassLoader() {
super(CustomClassLoader.class.getClassLoader()); // calls the parent
// class
// loader's
// constructor
}
public Class loadClass(String className) throws ClassNotFoundException {
return findClass(className);
}
public Class findClass(String className) {
byte classByte[];
Class result = null;
result = (Class) classes.get(className); // checks in cached classes
if (result != null) {
return result;
}
try {
return findSystemClass(className);
} catch (Exception e) {
}
try {
JarFile jar = new JarFile(jarFile);
JarEntry entry = jar.getJarEntry(className + ".class");
System.out.println(className+".class");
InputStream is = jar.getInputStream(entry);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
int nextValue = is.read();
while (-1 != nextValue) {
byteStream.write(nextValue);
nextValue = is.read();
}
classByte = byteStream.toByteArray();
result = defineClass(className, classByte, 0, classByte.length,
null);
classes.put(className, result);
System.out.println(">>>>result: " + result);
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
我还应该做什么?
您正试图将 Neo4j 和 Lucene 放在一个罐子里,对吧。
问题是,因为 Neo4j 使用旧的 Lucene 版本。
Alessandro Negro from GraphAware solved that problem and you can find his solution here - https://github.com/graphaware/neo4j-elasticsearch-tests
IMO 的问题是你是用一个 jar 启动你的数据库。您需要确保在您的类加载器中加载了启动 neo4j 所需的所有 jar
- 将此项目添加到 eclipse -> https://github.com/lagodiuk/neo4j-uber-jar.
- 使用
mvn-install
并创建~SNAPSHOT.jar
- 将
.jar
添加到您的项目(有冲突)
- 从该项目中删除
neo4j maven dependency
。
由于不同 .jar 文件中的不同 class 版本,我得到了这个异常:
java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, E:\neo4j at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:333) at org.neo4j.kernel.EmbeddedGraphDatabase.(EmbeddedGraphDatabase.java:63) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:92) at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69) at neo4j_lucene.conflict_solver.ConfilctSolver.createDb(ConfilctSolver.java:55) at neo4j_lucene.conflict_solver.ConfilctSolver.main(ConfilctSolver.java:35)
尽管我使用 ClassLoader
来解决这个问题,但我还是遇到了同样的异常。这是我的代码:
try {
CustomClassLoader ccl = new CustomClassLoader();
Object object;
Class clas;
clas = ccl
.loadClass("org.neo4j.graphdb.factory.GraphDatabaseFactory");
object = clas.newInstance();
graphDb = ((GraphDatabaseFactory) object)
.newEmbeddedDatabase(DB_PATH);
} catch (Exception e) {
e.printStackTrace();
}
自定义class加载程序代码:
public class CustomClassLoader extends ClassLoader {
private String jarFile = "C:/Users/RaufA/Desktop/test.jar"; // Path
// to
// the
// jar
// file
private Hashtable classes = new Hashtable(); // used to cache already
// defined classes
public CustomClassLoader() {
super(CustomClassLoader.class.getClassLoader()); // calls the parent
// class
// loader's
// constructor
}
public Class loadClass(String className) throws ClassNotFoundException {
return findClass(className);
}
public Class findClass(String className) {
byte classByte[];
Class result = null;
result = (Class) classes.get(className); // checks in cached classes
if (result != null) {
return result;
}
try {
return findSystemClass(className);
} catch (Exception e) {
}
try {
JarFile jar = new JarFile(jarFile);
JarEntry entry = jar.getJarEntry(className + ".class");
System.out.println(className+".class");
InputStream is = jar.getInputStream(entry);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
int nextValue = is.read();
while (-1 != nextValue) {
byteStream.write(nextValue);
nextValue = is.read();
}
classByte = byteStream.toByteArray();
result = defineClass(className, classByte, 0, classByte.length,
null);
classes.put(className, result);
System.out.println(">>>>result: " + result);
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
我还应该做什么?
您正试图将 Neo4j 和 Lucene 放在一个罐子里,对吧。
问题是,因为 Neo4j 使用旧的 Lucene 版本。
Alessandro Negro from GraphAware solved that problem and you can find his solution here - https://github.com/graphaware/neo4j-elasticsearch-tests
IMO 的问题是你是用一个 jar 启动你的数据库。您需要确保在您的类加载器中加载了启动 neo4j 所需的所有 jar
- 将此项目添加到 eclipse -> https://github.com/lagodiuk/neo4j-uber-jar.
- 使用
mvn-install
并创建~SNAPSHOT.jar
- 将
.jar
添加到您的项目(有冲突) - 从该项目中删除
neo4j maven dependency
。