Java | Use IntelliJ IDEA to package ordinary projects/Maven projects into jar files and run them

First of all, make sure that there are no errors in the program you wrote.

1. Packaging steps

1. General engineering

Click on the project structure=>Artifacts=>+Number=>JAR=>from models with dependencies...

Insert picture description here
Select main category

Insert picture description here
Insert picture description here
Modify Directory for META-INF/MANIFEST.MF:

The path is best to be at the same level as src, otherwise it is prone to problems. The author's actual test can also be placed in the resources folder.

Click OK

At this time, there will be a MANIFEST.MF file in the root directory of the project, which is a necessary file for the jar package. This file describes a lot of information about the Jar file, so I won’t give too much explanation here.

Insert picture description here

Finally Build Artifacts

Insert picture description here
Insert picture description here
The packaged jar file is in the out folder under the project root directory

Insert picture description here

2. Maven project

It is very user-friendly to use Maven directly for packaging.

Click on the right sidebar Maven=>Project name=>Lifecycle=>package=>Right click and select Run Maven Build

The packaged jar file is in the target folder under the project root directory
Insert picture description here

2. Run the jar package

Use command

java -jar xxx.jar

Insert picture description here
Spring boot has built-in Tomcat. When you see Tomcat start, it means that the jar package has run successfully (I set the Tomcat port to 8888, if you don’t set Tomcat’s default port to 8080)

Guess you like

Origin blog.csdn.net/y1534414425/article/details/105535593
Recommended