several ways the MAVEN project is packaged as a jar
Here is a collection of previously packaged MAVEN projects for jar packages in a variety of ways to package directly, do not package dependencies
Package directly, do not package dependent packages, package only the code in the project into the jar package. Add the following plugin to the Pom, and then perform the Maven install
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-compiler-plugin</artifactid>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
To output the dependent jar package to the Lib directory method
The
Prints the dependency package for the jar package in the project to the specified directory, modifying the outputdirectory configuration, such as the following ${project.build.directory}/lib. If you want the packaged jar package to run directly through the command, such as Java-jar Xx.jar, you also need to establish a manifest configuration classpathprefix corresponding to the configuration above, such as the output of the dependency jar package to Lib, The classpathprefix should also be specified as lib/, and the entry class for the program is specified, with the full class name of the entry class in the Configuration MainClass node.
This packaging is common to Java projects, whether it is a springboot project or a traditional Java project.
<plugins> <!--java compilation plug-in--> <plugin> <groupid>org.
Apache.maven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7<
/target> <encoding>UTF-8</encoding> </configuration>
</plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> & Lt;archive> <manifest> <ADDCLASSPATH>TRUE</ADDCLASSP Ath> <classpathPrefix>lib/</classpathPrefix> <ma Inclass>com.yourpakagEname.mainclassname</mainclass> </manifest> </archive> </configuration> </plugin> <plugin> <groupid>or
G.apache.maven.plugins</groupid> <artifactId>maven-dependency-plugin</artifactId>
<executions> <execution> <id>copy</id> <phase>install</phase> <goals> &L T;goal>copy-dependencies</goal> </goals> <configuration&
Gt <outputDirectory>${project.build.directory}/lib</outputDirectory> </CONFIGURATION&G
T
</execution> </executions> </plugin></plugins>
Sometimes for convenience, you can put classpath in the current directory, the default classpath will be in the jar package, you can add manifestentries configuration after the main method configuration, specify Classpath, such as:
<plugin> <groupId>org.apache.maven.plugins</groupId> < Artifactid>maven-jar-plugin</artifactid> <configuration> <classe Sdirectory>target/classes/</classesdirectory> <archive> ;manifest> <!--The entrance to the main function--> <mainclass>com.yourp Akagename.mainclassname</mainclass> <!--MANIFEST when packaged.
MF File not logged timestamp version--> <useUniqueVersions>false</useUniqueVersions> <addClasspath>true</addClasspath> <classpathprefix>lib/<
;/classpathprefix> </manifest> <manifestEntries> <class-path>.</class-path> </manifestEntries> </archive> < /configuration> </plugin>
To make a project dependency package and project a package
Packaging this way will call the dependencies and Project code in your project as a jar package, configured as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-assembly-plugin</artifactid>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.xxg.Main</mainClass>
</ manifest>
</archive>
<descriptorRefs>
<descriptorref>jar-with-dependencies </descriptorRef>
</descriptorRefs>
</configuration>
But this is no problem with traditional Java project packaging, as with the Spring Framework jar package. Can be packaged with a Maven-shade-plugin plug-in to implement the Spring Framework packaging springboot Project Packaging
The most common and easiest way to springboot project packaging is to use Springboot packaging plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-maven-plugin</artifactid>
</plugin>
Adding this plugin to the POM and clicking Maven [Install] or [repackge] will take all the current project dependencies and the current project's source code into a jar package, as well as a jar pack without a dependency pack. That's original . Groovy Project Packaging
If you include groovy code in your project, the groovy code will not be packaged by default when MAVEN is packaged, and you need to add the following configuration
<plugin> <groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId> <version>1.2</version>
<executions> <execution> <goals>
<goal>addSources</goal> <goal>addStubSources</goal>
<goal>compile</goal> <goal>execute</goal>
</goals> </execution> </executions> </plugin>