I'm using Intellij Java 2016.2.2 and Maven to create a very simple Java console application.
I want to add an external library, so I add my dependency in Maven like this:
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12</version>
</dependency>
It works fine when I run it in the IDE, but not in an external console (I have the following error: java.lang.NoClassDefFoundError).
I checked and for some reason, the external JAR is not added in the JAR I just generated. I also tried many things in "File -> Project Structure", but still not working...
I just want to build my JAR with my dependencies in it, so I can simply run my application in a console using:
java -jar myproject.jar
How can I do that? Thanks for your help!
I finally managed to generate this JAR with Intellij Java, here is how I do:
EDIT
A better (and easier way) to do it is adding the following lines in the pom.xml file :
then use the "clean" and "package" maven commands.
The last 3 steps above (about MANIFEST.MF) still seem to be mandatory.
Okay, so you basically want to create a "fat jar" (sometimes called assembly), that contains all its own dependencies (usually, the dependencies are external).
You need to use a Maven plugin for that. Below is a sample assembly plugin configuration jar-with-dependencies:
then, simply run