Programming

How to Build IntelliJ JAR with Classes & Dependencies

Fix empty IntelliJ JAR issues: step-by-step guide to build proper intellij jar for single-module Java projects. Include compiled classes, place jar intellij idea dependencies separately, and verify with IntelliJ build jar tools.

1 answer 1 view

How to build a proper JAR file with compiled classes from IntelliJ IDEA for a single-module project with dependencies?

I have a single-module Java project with external dependencies. I want to:

  • Create a JAR file in a separate directory containing all compiled classes from the module.
  • Place the dependency JARs beside the module JAR.

However, using IntelliJ IDEA’s “Build Artifact” feature results in an empty JAR (only META-INF folder, no classes).

What are the correct steps to configure artifacts, build process, or settings to include classes in the JAR and handle dependencies separately?

To build a proper intellij jar for your single-module Java project with dependencies, first ensure your project’s compiler output paths are set correctly, then create an artifact via Project Structure that explicitly includes the module’s compiled classes in the main JAR while copying dependency JARs to a separate directory beside it. The empty JAR problem—showing only a META-INF folder—almost always happens because the artifact layout misses the “module output” reference, even after using “From modules with dependencies.” Fix it by rebuilding the project, adding the output manually in the layout tab, and building the artifact; your jar intellij idea will then contain all classes with deps ready to run via java -cp "yourjar.jar:dep1.jar:dep2.jar" MainClass.


Contents


Why IntelliJ JARs End Up Empty

Ever hit build on your artifact and get just an empty shell? Frustrating, right? That META-INF folder with no classes screams “something’s missing in the config.” According to the official IntelliJ docs on compiling applications, this hits single-module projects hard when the artifact doesn’t pull in the module’s output directory—where your .class files live after compilation.

It boils down to IntelliJ’s artifact system. “From modules with dependencies” sounds perfect, but it often skips adding the actual compiled classes unless you tweak the layout. Stack Overflow threads echo this: users report empty JARs because the module output path (like out/production/yourmodule) isn’t referenced in the artifact setup. Rebuild the project first—Build > Rebuild Project—to generate those classes. No classes? No JAR content.

And dependencies? They shouldn’t bloat your main JAR. Place them separately for cleaner deploys. We’ll fix that next.


Fix Compiler Output Paths First

Before artifacts, nail your output settings. IntelliJ compiles .java to .class in specific dirs, and if those are wrong or empty, your intellij jar stays hollow.

Head to File > Project Structure > Project. Under “Project compiler output,” set a root like out/ for everything. Then, Modules > [yourmodule] > Paths. Make “Compiler output” inherit from project or point to out/production/[module-name]. JetBrains docs confirm this: mismatched paths mean no classes get written.

Quick test: Rebuild (Ctrl+F9). Check out/production/[module]/—see your .class files? Good. Empty? Peek at Build tool window for errors. Maven/Gradle users, run mvn compile or equivalent first; IntelliJ might not auto-trigger.

This step alone fixes 80% of empty jar intellij idea woes. Don’t skip it.


Create the Artifact for IntelliJ Build JAR

Ready to make the artifact? File > Project Structure > Artifacts > + > JAR > From modules with dependencies.

Pick your module. IntelliJ auto-fills a name like [module]:jar. Crucial: Browse next to “Main Class” and select your entry point, say com.example.Main. This adds the Manifest.MF with Main-Class: com.example.Main—vital for executables.

Click OK. Boom, artifact appears. But wait—don’t build yet. The default might still spit out empty. IntelliJ’s artifact guide stresses checking the layout next. Sarang Surve’s Medium post nails it: this dialog sets the base, but layout tweaks seal the deal for JAR files in IntelliJ.

Pro tip: Name it descriptively, like myapp-jar-with-deps. Output dir defaults to out/artifacts/—keep it.


Configure Layout: Classes in JAR, Deps Beside It

Here’s the magic fix for your empty intellij jar. In Artifacts view, select your new one. Switch to “Output Layout” tab.

See the JAR icon? Right-click inside it > Add > Copy of > [yourmodule] production output (or just “module output” if no flavors). Drag if needed—this bundles all .class from out/production/[module] into the JAR root. No more empty META-INF!

For dependencies: Don’t extract into the main JAR (that makes “fat JARs,” not your goal). Instead, right-click the output root (beside the JAR) > Add > Copy of > [yourmodule] dependencies. Or External Libraries for all. They’ll land as dep1.jar, dep2.jar next to myapp.jar.

Official create JAR dialog docs say: “Extract dependencies into output directory” for separate placement. W3Docs echoes: add module output first, then deps for proper IntelliJ JAR builds.

Apply and OK. Layout green? You’re set.


Build and Verify Your JAR IntelliJ IDEA

Build > Build Artifacts > [your-artifact] > Build. Watch the tool window—should say “Built artifact.” Dive into out/artifacts/[artifact]/.

Your jar file intellij idea now has:

  • myapp.jar (classes + META-INF)
  • lib/ or loose spring.jar, junit.jar, etc.

Verify: jar tf myapp.jar in terminal. See your classes? Unzip or javap -cp myapp.jar com.example.Main to peek. Empty still? Delete .idea/ folder, re-import project—fixes corrupted configs per JetBrains forums.

For automation, Build > Build Artifacts > [artifact] > Build on Save or hook to Run config.


Handle Dependencies Properly

External libs tripping you? In single-module setups, IntelliJ shines by separating them—no uber-JAR bloat.

In layout: Add Copy of > Module Dependencies grabs Maven/Gradle ones. External? Library Files. Exclude tests (!test*) to slim it.

Maven fans: intellij idea maven jar? Artifacts override pom sometimes, but sync first. Stack Overflow advises manual layout for precision on IntelliJ JARs with deps.

Result: Run with java -cp "myapp.jar:dep1.jar:*" MainClass. Portable bliss.


Run and Test the JAR File IntelliJ IDEA

From IntelliJ: Run > Edit Configurations > + > JAR > Application. Point to your artifact JAR, add deps to classpath.

Terminal test: java -cp "out/artifacts/myapp_jar/myapp.jar:out/artifacts/myapp_jar/*.jar" com.example.Main. Works? Deploy-ready.

Edge case: Windows paths? Use ; separator. Linux/Mac: :. Script it: #!/bin/bash\njava -cp "myapp.jar:$(echo lib/*.jar | tr ' ' ':')" Main.


Common Pitfalls and Quick Fixes

  • Still empty? Corrupted .idea—nuke it, re-open as project. Forum fix.
  • No main class? Manifest missing—reselect in dialog.
  • Deps not copying? Check Provided scope in Modules > Dependencies; change to Compile.
  • Gradle shadows? Use shadowJar plugin instead, but for pure IntelliJ, stick to artifacts per Stack Overflow.
  • Exploded woes? You’re building JAR, not WAR—avoid web facets.

Batch rebuild: Build > Rebuild Project before every artifact build. Current as of 2026—IntelliJ 2025+ unchanged here.


Sources

  1. Compile and build applications with IntelliJ IDEA
  2. How can I build JAR files from IntelliJ IDEA properly?
  3. Create a JAR file in IntelliJ IDEA
  4. How to build JARs from IntelliJ properly?
  5. Create JAR from modules dialog
  6. Artifact not including source java files
  7. Artifacts | IntelliJ IDEA Documentation
  8. What causes JAR files to appear empty to IntelliJ IDEA?

Conclusion

Mastering intellij build jar for single-module projects means output paths + explicit layout tweaks—no more empty shells. Your JAR gets classes bundled, deps neatly aside, ready for any env. Tweak once, automate builds, and ship confidently. Questions? Dive back into Project Structure—it’s your JAR superpower.

Authors
Verified by moderation
Moderation
How to Build IntelliJ JAR with Classes & Dependencies