How to build JARs from IntelliJ properly?
To build a JAR (Java Archive) file from IntelliJ IDEA, you need to follow these steps:
- Open your project in IntelliJ IDEA.
- Select the project in the Project pane on the left.
- Click on the "File" menu and select "Project Structure".
- In the "Project Structure" window, select "Artifacts" on the left.
- Click on the "Add" button and select "JAR" > "From modules with dependencies".
- In the "Create JAR from Modules" window, select the module that you want to include in the JAR file.
- Select the "Main Class" field and specify the fully-qualified name of the main class of your project (the class with the
public static void main(String[] args)
method). - Click on the "OK" button to close the window.
- Click on the "Apply" button and then on the "OK" button to close the "Project Structure" window.
- Click on the "Build" menu and select "Build Artifacts".
- In the "Build Artifacts" window, select the artifact that you want to build and click on the "Build" button.
The JAR file will be created in the "out/artifacts" directory of your project.
Alternatively, you can use the "Build > Build Artifacts > Build" command from the main menu, or use the "Build Artifacts" button in the toolbar.
Note that you need to have the "Artifact" plugin enabled in IntelliJ IDEA. This plugin is enabled by default, but you can check if it is enabled by going to "Settings > Plugins" and looking for the "Artifact" plugin in the list.