Intellij Maven: Create jar with all library dependencies

D. Müller :

Working with IntelliJ Idea, I want to implement the following:

I want to export an application to a jar, which contains all needed libraries. E.g. I need the AWS Java SDK libraries for S3 access, but if I upload the jar to the server and run the jar I get an NoClassDefFoundError, see below:

Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
    at java.lang.Class.getMethod0(Class.java:2866)
    at java.lang.Class.getMethod(Class.java:1676)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 6 more

Comparison: I created the same project in Eclipse and get no error! The jar file sizes are very different (Eclipse: ~35 MB vs. IntelliJ Idea: ~5,5 MB)!

I included the libraries via Maven and downloaded them also into the "lib" folder of my project: enter image description here

enter image description here

As parameter in the run configurations I set "package", see screenshot below: enter image description here

SOLUTION:

Thanks for all your hints, I got it to work now! The trick was that I did't add the dependencies to the pom.xml file (because I thought that this would be done automatically after setting them in the Project Structure, but it didn't)!!! See also my other question: Intellij IDEA Maven Plugin - Manage Dependencies and https://www.jetbrains.com/idea/help/maven.html! Add the dependencies by

  1. Open pom.xml
  2. Menu "Code" > "Generate" > "Dependency" (or shortcut ALT + INSERT)
Héctor :

You need to use Maven Assembly Plugin to include dependencies:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>your.package.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

and then: mvn clean compile assembly:single

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Maven not adding all dependencies to jar

From Java

Export maven as jar file with all dependencies

From Dev

remove all dependencies of a jar within a maven assembly

From

Force Intellij IDEA to reread all maven dependencies

From Dev

Intellij IDEA automatically resolving all maven dependencies

From Dev

Migrate from jCenter to MavenCentral, should I create a third party library JAR file containing all its dependencies?

From Java

Intellij Java 2016 & Maven : how to embed dependencies in JAR?

From Dev

Adding Javadoc of dependencies of a library from Maven in IntelliJ IDEA

From Java

Can the IntelliJ external maven library tell where the dependencies are from?

From Java

IntelliJ adding jar dependencies

From Java

How to produce an executable jar file with all maven dependencies?

From Dev

IntelliJ Error : "Cannot Resolve Symbol" in all maven dependencies

From Java

Maven jar with dependencies?

From Java

Including dependencies in a jar with Maven

From Dev

Building jar with dependencies maven

From Dev

How to create a jar with Maven that includes dependencies in a separate folder for each dependency

From Dev

How to create maven uber jar which includes dependencies with scope provided

From Java

How can I create an executable jar without dependencies using Maven?

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How can I create an executable/runnable JAR with dependencies using Maven?

From Dev

IntelliJ not reflecting Maven dependencies

From Java

Maven dependencies in IntelliJ project

From Dev

IntelliJ is not recognizing Maven Dependencies

From Java

How do I create a jar with all dependencies using Gradle 4.4?

From Dev

Create a library with dependencies in android

From Dev

Maven: Is it possible to create a fat jar containing only dependencies and a jar with only application code?

From Java

How to create a runnable jar with maven that includes dependencies in a separate "lib" folder (not an uber jar)

From Dev

Using maven assembly plugin to create ZIP file containing a fat jar (jar-with-dependencies)

From Java

Maven failing to download jar dependencies

Related Related

  1. 1

    Maven not adding all dependencies to jar

  2. 2

    Export maven as jar file with all dependencies

  3. 3

    remove all dependencies of a jar within a maven assembly

  4. 4

    Force Intellij IDEA to reread all maven dependencies

  5. 5

    Intellij IDEA automatically resolving all maven dependencies

  6. 6

    Migrate from jCenter to MavenCentral, should I create a third party library JAR file containing all its dependencies?

  7. 7

    Intellij Java 2016 & Maven : how to embed dependencies in JAR?

  8. 8

    Adding Javadoc of dependencies of a library from Maven in IntelliJ IDEA

  9. 9

    Can the IntelliJ external maven library tell where the dependencies are from?

  10. 10

    IntelliJ adding jar dependencies

  11. 11

    How to produce an executable jar file with all maven dependencies?

  12. 12

    IntelliJ Error : "Cannot Resolve Symbol" in all maven dependencies

  13. 13

    Maven jar with dependencies?

  14. 14

    Including dependencies in a jar with Maven

  15. 15

    Building jar with dependencies maven

  16. 16

    How to create a jar with Maven that includes dependencies in a separate folder for each dependency

  17. 17

    How to create maven uber jar which includes dependencies with scope provided

  18. 18

    How can I create an executable jar without dependencies using Maven?

  19. 19

    How can I create an executable JAR with dependencies using Maven?

  20. 20

    How can I create an executable/runnable JAR with dependencies using Maven?

  21. 21

    IntelliJ not reflecting Maven dependencies

  22. 22

    Maven dependencies in IntelliJ project

  23. 23

    IntelliJ is not recognizing Maven Dependencies

  24. 24

    How do I create a jar with all dependencies using Gradle 4.4?

  25. 25

    Create a library with dependencies in android

  26. 26

    Maven: Is it possible to create a fat jar containing only dependencies and a jar with only application code?

  27. 27

    How to create a runnable jar with maven that includes dependencies in a separate "lib" folder (not an uber jar)

  28. 28

    Using maven assembly plugin to create ZIP file containing a fat jar (jar-with-dependencies)

  29. 29

    Maven failing to download jar dependencies

HotTag

Archive