V
V
Vitaly the Wise2017-07-16 23:06:31
Java
Vitaly the Wise, 2017-07-16 23:06:31

What dependencies are needed for a robotic java project?

Hello. I am writing a project, but I ran into a launch problem. Here is what I use in the project:

import static com.codeborne.selenide.Selenide.*;
import com.codeborne.selenide.SelenideElement;
import com.devcolibri.ssl.Sender;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;
import org.bson.types.ObjectId;

Here are my dependencies:
<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.codeborne</groupId>
      <artifactId>selenide</artifactId>
      <version>4.5.1</version>
    </dependency>

    <dependency>
      <groupId>javax.mail</groupId>
      <artifactId>mail</artifactId>
      <version>1.4</version>
    </dependency>

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

    <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver-core</artifactId>
      <version>3.4.2</version>
    </dependency>

    <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>bson</artifactId>
      <version>3.4.2</version>
    </dependency>
  </dependencies>

When I run the project through the console java -jar my-app-1.0.jar from the target folder, an error pops up:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/bson/conversions/Bson
  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.bson.conversions.Bson
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

Please help me fix it. Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Albert Gazizov, 2017-07-17
@tapinambur0508

The project is going - it means that everything is in order with the dependencies. And the dependencies necessary to launch the project are exactly the same ones that are indicated in the pom file + the dependencies of the libraries used.
The problem is caused by the fact that when you run the built project, its dependencies were not found on the classpath.
To correct the situation you need:

  • Or, along with your jar, supply all the dependencies. for example by copying all the dependencies to the target directory using the Maven Dependency Plugin . An example of usage is here .
  • Or build a jar that includes all dependencies, see jar-with-dependencies https://javatalks.ru/topics/37400 .

K
Kirill Romanov, 2017-07-16
@Djaler

>Caused by: java.lang.ClassNotFoundException: org.bson.conversions.Bson
Chukchi is not a reader?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question