The MAVEN program is packaged into a single jar Part 1--MAVEN Assembly plugin

Source: Internet
Author: User
Tags unpack

The

Describes how to use the assembly package configuration file before, and here's how to package the entire project into a single executable jar. During system testing, a separate jar is required to test with the other integration team. For the first time, the jar package was chosen with assembly plugin, because our test program was inside Src/test/java, and assembly could automatically pack the test package and test dependencies, as follows:
1. Create Package Test Class and Test dependency's assembly configuration file Package.xml in src/main/resources/assembly/:

<assembly xmlns= "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi= "http:// Www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/plugins/maven-assembly-plugin/ assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd "> <id>test-executable</id> <forma ts> <format>jar</format> </formats> <includebasedirectory>false</includebase directory> <dependencySets> <dependencySet> <outputdirectory>/</outputdire Ctory> <useProjectArtifact>true</useProjectArtifact> *<unpack>true</unpack > <scope>test</scope>* </dependencySet> </dependencySets> <files
            Ets> <fileSet> <directory>${project.build.directory}/classes</directory> <outputdirectory>/</outputdirectory> <includes> <include>**/*</include> &LT;/INCLUDES&G
            T <useDefaultExcludes>true</useDefaultExcludes> </fileSet> <fileSet> ;d irectory>${project.build.directory}/test-classes</directory> <outputdirectory>/</outputdir
            ectory> <includes> <include>**/*</include> </includes> <useDefaultExcludes>true</useDefaultExcludes> </fileSet> </fileSets> </ Assembly>
To create a Maven-assembly-plugin package configuration:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2 .3</version> <configuration> <descriptor>src/main/resources, assembly
                    /package.xml</descriptor> </configuration> <executions> <execution> <id>make-package</id> <phase>packa
                        Ge</phase> <goals> <goal>single</goal>
                                </goals> <configuration> <archive> <manifest> <!--main class--> <mainclas S>com.cloud ..... Publishertest</mainclass> </manifest> </archive
>                        </configuration> </execution> </executions> </plugin>

After executing maven package, there will be *-test-executable.jar in target folder containing all the required class files. This packaging is problematic, however, because a file assembly with the same name will be ignored directly, and for spring-related jars, XSD files are saved in Meta-inf (Meta-inf/spring.handlers and meta-inf/ Spring.schemas), so packing can cause many XSD to be unresolved without a network, and the following questions are reported:

Unable to locate Namespacehandler when using * * *

This time you will need to use Maven-shade-plugin, as described in the next article.

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.