由于不同 .jar 文件中的不同类版本,我遇到了以下异常:
java.lang.RuntimeException:启动org.neo4j.kernel.EmbeddedGraphDatabase,E:\ neo4j时出错 在org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:333) 在org.neo4j.kernel.EmbeddedGraphDatabase。(EmbeddedGraphDatabase.java:63) at org.neo4j.graphdb.factory.GraphDatabaseFactory $ 1.newDatabase(GraphDatabaseFactory.java:92) at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69) 在neo4j_lucene.conflict_solver.ConfilctSolver.createDb(ConfilctSolver.java:55) 在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();
}
自定义类加载器代码:
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;
}
}
}
我还应该怎么办?
答案 0 :(得分:2)
你正试图将Neo4j和Lucene放在一个罐子里,对吧。
问题是,因为Neo4j使用旧的Lucene版本。
来自https://github.com/box/box-windows-sdk-v2的Alessandro Negro解决了这个问题,你可以在这里找到他的解决方案 - GraphAware
答案 1 :(得分:2)
IMO问题是你用一个jar启动你的数据库。您需要确保在类加载器中加载启动neo4j
所需的所有jar答案 2 :(得分:0)
mvn-install
并创建~SNAPSHOT.jar
.jar
添加到您的项目(有冲突)neo4j maven dependency
。