IDEA makes a runnable jar package, detailed teaching

idear packaging report: There is no main manifest attribute in jar

  1. One of the methods for java to generate executable jar files:
    1.1 (1) InteliJ IDEA menu bar File—>Project Structure—>Artifacts—>"+"Operation—>Select JAR—>Select "From modules with dependencies...", as follows :
    insert image description here
    Click to add jar package,
    insert image description here
    select the second one
    insert image description here
    , select your project, your main method

The most important thing is to choose a Main Class, and then the system defaults to modify the path of META-INF/MANIFEST.MF to src (be careful not to put it in the main/java directory, otherwise META-INF/MANIFEST. MF does not contain Main Class information, and when generating an executable jar, it will prompt that there is no main list attribute) By default, the
second-level directory behind X:\your project directory\src\main\java needs to be deleted! ! ! ! !

  1. Add a Module Output, this key, must have, otherwise
    insert image description here

insert image description here
Save after adding

  1. After completing the above steps, select Build Artifacts in the IntelliJ IDEA menu column and build. If there is no accident, the corresponding jar package file will be generated under your project. The default location is in the directory out/artifacts/${project Name}, and then run it directly on the terminal:
    insert image description here
    the decompressed jar package looks like this.
    insert image description here

So far, execute java -jar ×××.jar and you can see the output
insert image description here

Welcome to leave a message

Guess you like

Origin blog.csdn.net/qq_42673067/article/details/130045767