How to build JARs from IntelliJ IDEA properly?

artifact, build, intellij-idea, jar, java

Solution

Instructions:

File -> Project Structure -> Project Settings -> Artifacts -> Click + (plus sign) -> Jar -> From modules with dependencies...

Select a Main Class (the one with `main()` method) if you need to make the jar runnable.

Select Extract to the target Jar

Click OK

Click Apply/OK

The above sets the "skeleton" to where the jar will be saved to. To actually build and save it do the following:

Build -> Build Artifact -> Build

Try Extracting the .jar file from:

ProjectName
 ┗ out
   ┗ artifacts
     ┗ ProjectName_jar
        ┗ ProjectName.jar

References:

- (Aug 2010) http://blogs.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ (Here's how to build a jar with IntelliJ 10)

- (Mar 2023) https://www.jetbrains.com/help/idea/compiling-applications.html#package_into_jar

Problem

I have a project that contains a single module, and some dependencies. I'd like to create a JAR, in a separate directory, that contains the compiled module. In addition, I would like to have the dependencies present beside my module. No matter how I twist IntelliJ's "build JAR" process, the output of my module appears empty (besides a `META-INF` file).

Original source

Related problems