Three ways maven hits a jar package does not include a dependent jar package
The method packages the jar, does not contain a dependent jar package, and does not specify an ingress class.
<build> <plugins> <plugin> <!-- 指定项目编译时的java版本和编码方式 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <target>1.8</target> <source>1.8</source> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins></build>
Output the dependent jar package to the specified directory
The jar that the method packs, specifies the ingress class, can be executed directly using the Java-jar Project.jar
,
But a third-party dependency exists under a specified external directory, and migration requires that the jar and dependent directories be migrated together.
<build> <plugins> <plugin> <!--Specify the Java version and encoding for Project compilation-<groupi D>org.apache.maven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <target>1.8</target> <source>1.8</source> <encoding>UTF-8</encoding> </con figuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid > <artifactId>maven-jar-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> < ;mainclass>com.netty.client.signalclient</mainclass> <!--Specify entry class--<addclasspath >true</addclasspath> <!--generate Classpath properties in the jar's MF file-<classpathPrefix>lib/</classpathPrefix> &L t;! --classpath prefix, which is the path of the dependent jar package-</manifest> </archive> </conf iguration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid& Gt <artifactId>maven-dependency-plugin</artifactId> <version>3.1.1</version> &L t;executions> <execution> <id>copy</id> <phas E>install</phase> <goals> <goal>copy-dependencies</goal& Gt </goals> <configuration> <!--Specifies the output path of the dependent package, which needs to be consistent with the classpathprefix above -<outputdirectory>${project.build.directory}/lib</outputdirectory&Gt </configuration> </execution> </executions> </plugin> </plu Gins></build>
Make project dependencies and projects into a jar package
The method packages The jar, specifies the entry class, can be directly used to java -jar project.jar
execute,
and third-party dependencies are hit into the project jar package.
<build> <plugins> <plugin> <!--Specify the Java version and encoding for Project compilation-<groupi D>org.apache.maven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <target>1.8</target> <source>1.8</source> <encoding>UTF-8</encoding> </con figuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid > <artifactId>maven-assembly-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> <mainClass>com.netty.client.SignalClient</mainClass> <!--Specify the entry class path--</manifest > </archive> <descriptorRefs> <DESCRIPTORREF>JAR-WITH-DEPENDENCIES</DESCR Iptorref> <!--jar package suffix, generated in the form of jar package: Project-1.0-snapshot-jar-with-dependencies.jar---</descripto Rrefs> </configuration> <!--after adding this item, you can use the MVN package directly | MVN install--<!--do not add this item, you need to use MVN package directly assembly:single--<executions> <execution> <id>make-assembly</id> <phase>package< /phase> <goals> <goal>single</goal> < /goals> </execution> </executions> </plugin> </plugins>< /build>
Three ways maven hits a jar package