1

I have generated the executable fat jar file in java with the following dependencies

<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.function.thumbnail</groupId>
    <artifactId>Thumbnail</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Thumbnail</name>
    <url>http://maven.apache.org</url>
    <dependencies>

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.2.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.imgscalr/imgscalr-lib -->
        <dependency>
            <groupId>org.imgscalr</groupId>
            <artifactId>imgscalr-lib</artifactId>
            <version>4.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <!--Amazon s3 bucket -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.9.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>
    <build>

        <finalName>dateutils</finalName>
        <plugins>
 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.function.thumbnail.ThumbnailGenarationStandAloneFunctionality</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
        </plugins>

    </build>
</project>

I have tried mvn install command in command-prompt jar generated successfully after that I have tried to run jar at that time the above issues raised.

 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(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoException
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

can you please suggest How to Create the Executable JAR file with resources and dependencies using Maven in Eclipse

newbie
  • 456
  • 1
  • 6
  • 17
  • Possible duplicate of [How can I create an executable JAR with dependencies using Maven?](https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) – s7vr Jan 31 '18 at 14:56
  • I have tried this one too jar generated successfully but when am running the jar at that time the above issue raised `Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/MongoException ` – newbie Jan 31 '18 at 14:59
  • May be jar is generated successfully without dependencies. Check the jar to see if it contains mongodb dependency. – s7vr Jan 31 '18 at 15:05
  • I have added all dependencies in `pom.xml` file – newbie Jan 31 '18 at 15:10
  • Sorry I don't have the setup to test this for you but you need to update plugin config to include assembly plugin as suggested in the linked duplicate to include the dependencies in your jar. – s7vr Jan 31 '18 at 15:47
  • **thank you** as u suggested I have used following dependency it's working fine ` maven-assembly-plugin fully.qualified.MainClass jar-with-dependencies ` – newbie Feb 01 '18 at 06:51

0 Answers0