使用MongoDB运行Java文件时出现JNI错误

时间:2017-07-10 11:08:41

标签: java mongodb maven

我有一个非常简单的Java文件,它与数据库交互只是为了测试它是否正常工作。我能够编译Java文件但是当它运行时我得到一个JNI错误。

    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/MongoException
         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: com.mongodb.MongoException
         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文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>

     <groupId>Liam</groupId>
     <artifactId>Joy</artifactId>
     <version>1.0-SNAPSHOT</version>

     <dependencies>
         <dependency>
             <groupId>org.mongodb</groupId>
             <artifactId>mongo-java-driver</artifactId>
             <version>3.4.2</version>
         </dependency>
     </dependencies>

</project>

任何想法是什么问题?

0 个答案:

没有答案