'Can't create an executable jar with all dependencies

I want to create an executable jar with all dependencies so that I can deploy it later on AWS.

I tried out several different methods. They all produce a jar file, but executing it yields nothing (see below).

The first method involved using IntelliJ. I did the following: File -> Project Structure -> Artifacts -> Added jar -> Selected Main Class -> Build -> Build Artifacts -> Build. Afterwards, I executed the created JAR. I received the following error: no main manifest attribute, in benchmark.JAR.

So I decided to add the MANIFEST.MF manually:

Manifest-Version: 1.0
Main-Class: Benchmark
Class-Path: .

...and built the JAR using IntelliJ. I ended up having about 30 different jars. After I have executed benchmark.JAR, I got: CP:/Users/.../benchmark.jar.

I decided to try something else, namely the maven-jar-plugin. I added the following configuration to the pom.xml:

    <plugin>
      <!-- Build an executable JAR -->
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.2.2</version>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>Benchmark</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>

This didn't work either. I executed jar:jar and found the following error: Error: Unable to initialize main class Benchmark Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory

Undismayed I tried another option which is the spring-boot-maven-plugin: Please note: my project is not a spring-boot project.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <executable>true</executable>
                <classifier>spring-boot</classifier>
                <mainClass>Benchmark</mainClass>
            </configuration>
        </execution>
    </executions>
</plugin>

I executed clean, install, and repackage. I obtained the JAR, executed it, received: CP:benchmark.jar.

Then came the turn for the maven-shade-plugin. I executed shade, package+shade, package - unfortunately to no avail. I have: CP:benchmark.jar%


  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <transformers>
                    <transformer implementation=
                                            "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>Benchmark</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

What am I doing wrong?

EDIT:

According to the comment, I also tried with the maven-assemble-plugin. It doesn't work either. It gives me: CP:benchmark.jar

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>
                                    Benchmark
                                </mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source