0

In my Maven project, I added a dependency for the MongoDB java driver. But when I try to run the program, it produces:

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)

So I right-clicked on my project, and went to Run As -> Run Congfigurations... -> Classpath, and I found that the MongoDB jar wasn't added:

The Classpath tab under Run Configurations

Will adding my MongoDB jar to the Classpath tab resolve the NoClassDefFoundError? If so, how do I go about doing this?

My pom.xml file, if needed:

<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>

Any help would be much appreciated.

PickleDonk
  • 75
  • 1
  • 8
  • After you modified the `pom.xml`, did you make sure to right-click on the project and under the Maven menu, tell it to update? – nitind May 21 '19 at 01:27
  • @nitind After reading your comment I right-clicked on my project and updated it through `Maven -> Update Project...`, but it still does not work. – PickleDonk May 21 '19 at 01:34

0 Answers0