Idea packaging executable jar package
1. Reference materials
Idea package java executable jar package
Intellij Idea packages the java project into a jar, and cmd runs the jar
2. Operation steps
-
Right click on the project and select [Open Module Settings]
-
选择【Artifacts】–>【JAR】–>【From modules with dependencies…】
-
Select [Main Class (the program is started from the main method of this class)], it is recommended to put the generated [
META-INF/MANIFEST.MF
] in the main directory of the project, and click [OK] -
After the creation is complete, as shown in the figure, we will place the generated JAR package in the project main directory and check [Include in project build], which means that when the project executes the Build operation, a new JAR package will be generated
-
The first way to generate a JAR package: because we checked [Include in project build], we only need to execute the [Build Project] command to generate a new JAR package
-
The second way to generate a JAR package:
-
Click the [Build Artifacts] button
-
Execute Build command
-
-
The implementation of projects under the home directory
java -jar
command -
Note: META-INF folder and generate the required JAR package is located in the same directory, otherwise
java -jar
the command prompt will appear as follows: [xxx.jar no master list of attributes]
-
Analysis of reasons: If you lose the MANIFEST.MF file, then execute
java -jar
the command will not be able to find the main class to start, it will not report the error to find the main list of attributes. PS: If the MANIFEST.MF file has been modified (even if the file is cut away and then cut back intact), then you need to execute the Rebuild command, otherwise it will still report the error that the main list attribute is not found -
JAR package structure
-
Finish work, go to bed~