Home >Java >javaTutorial >How Do I Create a JAR File with Dependencies in IntelliJ IDEA?

How Do I Create a JAR File with Dependencies in IntelliJ IDEA?

Barbara Streisand
Barbara StreisandOriginal
2024-12-17 19:20:121015browse

How Do I Create a JAR File with Dependencies in IntelliJ IDEA?

Creating JARs with IntelliJ IDEA: A Comprehensive Guide

Q: How do I create a JAR file containing compiled code and dependencies?

A: Building JARs in IntelliJ IDEA:

To build a JAR with IntelliJ IDEA, follow these instructions:

  1. Open File > Project Structure.
  2. Navigate to Project Settings > Artifacts.
  3. Click the (plus sign) > JAR > From modules with dependencies....
  4. Select a Main Class (containing the main() method) if desired.
  5. Check Extract to the target Jar.
  6. Click OK.
  7. Click Apply or OK.

This sets up the JAR configuration. To build and save the JAR:

  1. Go to Build > Build Artifact.
  2. Select the JAR artifact you created.
  3. Click Build.

The JAR will be saved in the following directory:

?ProjectName
|
┗ ?out
|
┗ ?artifacts
|
┗ ?ProjectName_jar
|
┗ ?ProjectName.jar

References:

  • (Aug 2010) [Quickly Create JAR Artifact](http://blogs.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/)
  • (Mar 2023) [Packaging into JAR](https://www.jetbrains.com/help/idea/compiling-applications.html#package_into_jar)

The above is the detailed content of How Do I Create a JAR File with Dependencies in IntelliJ IDEA?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn