1. Modify Pom.xml Add the following content
<Build> <pluginmanagement> <Plugins> <plugin> <groupId>Org.apache.maven.plugins</groupId> <Artifactid>Maven-jar-plugin</Artifactid> <Configuration> <Archive> <Manifest> <MainClass>Com.jimson.hellojava.main</MainClass> <Addclasspath>True</Addclasspath> <Classpathprefix>lib/</Classpathprefix> </Manifest> </Archive> <classesdirectory> </classesdirectory> </Configuration> </plugin> </Plugins> </pluginmanagement></Build>
Run MVN clean package;
2. MAVEN packages the dependent jar package together
<Build> <Plugins> <plugin> <Artifactid>Maven-assembly-plugin</Artifactid> <Configuration> <Archive> <Manifest> <MainClass>Com.jimson.hellojava.main</MainClass> </Manifest> </Archive> <Descriptorrefs> <Descriptorref>Jar-with-dependencies</Descriptorref> </Descriptorrefs> </Configuration> </plugin> </Plugins> </Build>
To package a dependent package together, you need to use the Maven-assembly-plugin plugin. It is important to note that when you use this plug-in for packaging, you are no longer using the MVN Package command, but instead use the MVN assembly:assembly command.
After successful execution, a jar package with-jar-with-dependencies end is given in the target folder. This jar contains all the dependent packages for the current project and can be executed independently.
Two ways that Maven can package executable jars