我复制并沿用了辅导科的简单新4j例子,但现在我看上去:
[INFO] Surefire report directory: /home/kama/ws-git/neo4jexample/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@17bd6a1
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.995 sec <<< FAILURE!
Results :
Failed tests: firstTest(com.soebes.tutorials.Neo4JAppTest): com/soebes/tutorials/neo4jexample/RelationTypes
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
详细错误信息:
java.lang.NoClassDefFoundError: com/soebes/tutorials/neo4jexample/RelationTypes
at com.soebes.tutorials.neo4jexample.Neo4JApp.createDb(Neo4JApp.java:44)
at com.soebes.tutorials.neo4jexample.Neo4JApp.main(Neo4JApp.java:25)
at com.soebes.tutorials.Neo4JAppTest.firstTest(Neo4JAppTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:758)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
at org.testng.TestNG.run(TestNG.java:974)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:76)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:161)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:101)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Caused by: java.lang.ClassNotFoundException: com.soebes.tutorials.neo4jexample.RelationTypes
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
来源法就是这样:
public class Neo4JApp {
private String greeting;
private GraphDatabaseService graphDb;
private Node firstNode;
private Node secondNode;
private Relationship relationship;
public static void main(final String[] args) {
Neo4JApp hello = new Neo4JApp();
hello.createDb(args[0]);
hello.removeData();
hello.shutDown();
}
void createDb(String path) {
clearDb(path);
graphDb = new EmbeddedGraphDatabase(path);
registerShutdownHook(graphDb);
Transaction tx = graphDb.beginTx();
try {
firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
relationship = firstNode.createRelationshipTo(secondNode, RelationTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
System.out.print(firstNode.getProperty("message"));
System.out.print(relationship.getProperty("message"));
System.out.print(secondNode.getProperty("message"));
greeting = ((String) firstNode.getProperty("message"))
+ ((String) relationship.getProperty("message"))
+ ((String) secondNode.getProperty("message"));
tx.success();
} finally {
tx.finish();
}
}
private void clearDb(String path) {
try {
FileUtils.deleteRecursively(new File(path));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
void removeData() {
Transaction tx = graphDb.beginTx();
try {
firstNode.getSingleRelationship(RelationTypes.KNOWS, Direction.OUTGOING).delete();
firstNode.delete();
secondNode.delete();
tx.success();
} finally {
tx.finish();
}
}
void shutDown() {
System.out.println();
System.out.println("Shutting down database ...");
graphDb.shutdown();
}
private static void registerShutdownHook(final GraphDatabaseService graphDb) {
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running example before it s completed)
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
graphDb.shutdown();
}
});
}
而旧的“相邻”类则认为:
public enum RelationTypes implements RelationshipType {
KNOWS,
WHOKNOWS,
}
目前看不到问题吗? 相关不动产在正确地点界定...... 难道有人对我有 h?