Use MAVEN to package a project into a runnable jar note two points
1. Copying other jars that the project relies on
After packaging, run the following command to copy the dependent jar to the Target/lib directory
MVN Dependency:copy-dependencies-doutputdirectory=target/lib
2. The meta-inf\manifest of the generated jar package. MF file specifies the information for Main Class
Join in Pom.xml file
<build> <plugins> <plugin> <groupId> org.apache.maven.plugins</groupid> <artifactid>maven-jar-plugin</ artifactid> <configuration><archive> <manifest> < Mainclass>org. Main</mainclass> <addclasspath >true</addClasspath> < classpathprefix>lib/</classpathprefix> </manifest></archive> </configuration></plugin> <plugins></build>
which
<mainclass>org. Main</mainclass> Specifies the class where the Main method resides
<classpathPrefix>lib/</classpathPrefix> Specifies Classpath, the runtime only needs to Java-jar Xxx.jar command, do not need to specify with-CP
Maven packaged to run jar