IDEA package executable jar package

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

  1. Right click on the project and select [Open Module Settings]

    image-20210129231853604

  2. 选择【Artifacts】–>【JAR】–>【From modules with dependencies…】

    image-20210129232311381

  3. 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]

    image-20210129235548495

  4. 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

    image-20210129235657022

  5. 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

    image-20210129233814200

  6. The second way to generate a JAR package:

    1. Click the [Build Artifacts] button

      image-20210129234138201

    2. Execute Build command

      image-20210129234216513

  7. The implementation of projects under the home directory java -jarcommand

    image-20210129235822356

  8. Note: META-INF folder and generate the required JAR package is located in the same directory, otherwise java -jarthe command prompt will appear as follows: [xxx.jar no master list of attributes]

image-20210130000029668

  1. Analysis of reasons: If you lose the MANIFEST.MF file, then execute java -jarthe 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

    image-20210130212915649

  2. JAR package structure

    image-20210130115453976

  3. Finish work, go to bed~

Guess you like

Origin blog.csdn.net/oneby1314/article/details/113414648