2012-04-08 39 views
0

我已複製並從教程部粘貼在簡單的Neo4j例如但目前我得到了消息:Neo4實施例不工作 - 類未發現

[INFO] Surefire report directory: /home/kama/ws-git/neo4jexample/target/surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running TestSuite 
Configuring TestNG with: [email protected]6a1 
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(); 
     } 
    }); 
    } 

和所使用的類RelationTypes看起來像這樣:

public enum RelationTypes implements RelationshipType { 
    KNOWS, 
    WHOKNOWS, 
} 

該項目可在github找到。

目前我沒有看到問題?... RelationTypes被定義在正確的位置...可能有人對我有暗示嗎?

回答

0

問題是單元測試目錄不允許成爲目標文件夾本身。它必須是目標下的單獨文件夾。

+0

很好,謝謝你回報! – 2012-04-11 07:27:59