How to build JARs from IntelliJ properly?

To build a JAR (Java Archive) file from IntelliJ IDEA, you need to follow these steps:

  1. Open your project in IntelliJ IDEA.
  2. Select the project in the Project pane on the left.
  3. Click on the "File" menu and select "Project Structure".
  4. In the "Project Structure" window, select "Artifacts" on the left.
  5. Click on the "Add" button and select "JAR" > "From modules with dependencies".
  6. In the "Create JAR from Modules" window, select the module that you want to include in the JAR file.
  7. 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).
  8. Click on the "OK" button to close the window.
  9. Click on the "Apply" button and then on the "OK" button to close the "Project Structure" window.
  10. Click on the "Build" menu and select "Build Artifacts".
  11. 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.