在我的Maven项目中,我为MongoDB Java驱动程序添加了一个依赖项。但是当我尝试运行该程序时,它会产生:
java.lang.NoClassDefFoundError: com/mongodb/MongoClient
com.therapy.Test.doGet(Test.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
因此,我右键单击我的项目,然后转到Run As -> Run Congfigurations... -> Classpath
,发现没有添加MongoDB jar:
将我的MongoDB jar添加到Classpath
选项卡可以解决NoClassDefFoundError
吗?如果是这样,我该怎么做?
我的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>CulminatingVer7Server</groupId>
<artifactId>CulminatingVer7Server</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>CulminatingVer7Server Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.6.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>CulminatingVer7Server</finalName>
</build>
</project>
任何帮助将不胜感激。