我正在尝试使用maven运行此处(https://neo4j.com/developer/java/)所述的基本neo4j Java程序。
尽管我可以成功编译,但是当我运行它时,我得到了一个运行时异常,表明程序无法找到类,如下所示。
java com.ravi.nFourJ.App
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/neo4j/driver/v1/TransactionWork
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.neo4j.driver.v1.TransactionWork
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
这是我的pom.xml文件。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ravi.nFourJ</groupId>
<artifactId>n4-java</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>n4-java</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>1.4.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.neo4j/neo4j-kernel -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>3.5.0-alpha03</version>
</dependency>
</dependencies>
</project>
我做了mvn编译,它在项目目录下创建了一个名为“ target”的文件夹。
└── target
├── classes
│ └── com
│ └── ravi
│ └── nFourJ
│ ├── App$1.class
│ └── App.class
└── maven-status
└── maven-compiler-plugin
└── compile
└── default-compile
├── createdFiles.lst
└── inputFiles.lst
导航到“ target / classes”目录并运行程序之后
java com.ravi.nFourJ.App
出现上述错误。
答案 0 :(得分:1)
通过执行java com.ravi.nFourJ.App
,您正在运行该类,但是没有任何类路径(即deps)。
我建议您改用此命令:mvn exec:java -Dexec.mainClass="com.ravi.nFourJ.App"