Maven Combat (v) How to make it easier to extract a third party package by using a project developed by Maven

Source: Internet
Author: User
Tags unpack

If your project is built with Maven, you may encounter such problems when the project is online and deployed to the server. The problem is that there is no MAVEN environment on the server, that is, the jar packages in the warehouses (repository) that the project relies on, you need to extract them separately and upload them to the server, the solution:

Pre: Install complete maven in eclipse (specifically participate in pre-maven combat) and project for the ' Maven WebApp project ' type, taking spring-petclinic as an example

Approach 1:MVN Package

Pom.xml:<packaging> is war, MVN package's command calls the project-dependent jar package to the Lib folder under Web-inf, as shown in the figure:

, and the console prompts the war package location information when completed


Approach 2:MVN assembly:assembly

The newly generated {Artifactid}-jar-with-dependencies.jar file is found under the ${project}/target folder, and during the execution of the command, MAVEN exports the packages that the jar package relies on. and unpack (unpackage), put together in this {Artifactid}-jar-with-dependencies.jar package

Note: pom.xml:

<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
This jar-with-dependencies is a assembly written, assembly description Reference (assembly descriptor)


Option 3: Separate deployment by third party package

A: Modify the Pom.xml <descriptorRef>jar-with-dependencies</descriptorRef> path, modified to: <descriptorref>src/ Main/assembly/src.xml</descriptorref>

B: Create the Src.xml file under the project name/src/main/assembly:

<assembly
Xmlns= "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http:// Maven.apache.org/xsd/assembly-1.1.0.xsd ">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>

C: Re-execute MVN assembly:assembly

This will see the newly created {Artifactid}-jar-with-dependencies.jar in the target folder, where all the third-party packages that the project relies on are packaged in the same type.




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.