I just finished my first application and I now would like to create one executable jar that I can send to other people so they can use the application I wrote.
I might me completely off course. If so please inform me what I am doing wrong.
I am running the following command in my command prompt (cmd): mvn clean package. This is not giving me any errors.
When I try to run the application using: java -jar AppName.jar. It executes but gives the following error while running:
Exception in thread "main" java.lang.NoClassDefFoundError: net/lingala/zip4j/exception/ZipException
at CompressedFileOpener.CompressedFileOpener.CompressedOpenerFactory.getOpener(CompressedOpenerFactory.java:12)
at CompressedFileOpener.CompressedFileOpener.App.main(App.java:15)
Caused by: java.lang.ClassNotFoundException: net.lingala.zip4j.exception.ZipException
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)
... 2 more
My pom.xml file looks like:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CompressedFileOpener</groupId>
<artifactId>CompressedFileOpener</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CompressedFileOpener</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>CompressedFileOpener.CompressedFileOpener.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Edit: I managed to solve my issue by using the comment section below this post and searching for fat jar.
Adding the follwing to my build path in my pom.xml file created one single jar containing all dependencies as well.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>CompressedFileOpener.CompressedFileOpener.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>