Three ways maven hits a jar package

Source: Internet
Author: User

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> &lt ;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> &LT;DESCRIPTORREF&GT;JAR-WITH-DEPENDENCIES&LT;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.