Adding external library to artifact jar in IntelliJ IDEA

You have 2 options here:

  • extract the dependency into the artifact jar so that the app is the single executable jar with all the dependencies
  • link the dependent jars via the Manifest.MF and copy them near the application main jar

I've prepared a sample project that demonstrates both approaches: HelloWithDependencies.zip.

The artifacts are produced into out\single and out\linked directories.

Relevant configurations:

single

linked


If you are using maven to build your application then this is not the correct way to add external library. You should either

  1. Do an install of your library like below mvn install:install-file -Dfile=myJar.jar -DgroupId=com.yourproject -DartifactId=yourproject -Dversion={version} -Dpackaging=jar.
  2. Use system path like explained here.

Option 1 is prefered since you don't have to keep jar in your project.