Add dependency packages and join local dependency packages when MAVEN is packaged

Source: Internet
Author: User

MAVEN does not add dependent jar packages by default, so it is not possible to mvn clean install packages directly if you want to run a standalone jar package. Need to change the pom file slightly, add the following plugin

<Build>        <sourcedirectory>Src/main/java</sourcedirectory>        <Plugins>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <Artifactid>Maven-compiler-plugin</Artifactid>                <Configuration>                    <Defaultlibbundledir>Lib</Defaultlibbundledir>                    <Source>1.5</Source>                    <Target>1.5</Target>                    <encoding>UTF-8</encoding>                </Configuration>            </plugin>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <Artifactid>Maven-jar-plugin</Artifactid>                <Configuration>                    <Archive>                        <Manifest>                            <Addclasspath>True</Addclasspath>                            <Classpathprefix></Classpathprefix>                            <MainClass>com.xx.xx.xx</MainClass>                        </Manifest>                    </Archive>                </Configuration>            </plugin>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <Artifactid>Maven-dependency-plugin</Artifactid>                <executions>                    <Execution>                        <ID>Copy</ID>                        <Phase>Install</Phase>                        <Goals>                            <goal>Copy-dependencies</goal>                        </Goals>                        <Configuration>                            <outputdirectory>${project.build.directory}</outputdirectory>                        </Configuration>                    </Execution>                </executions>            </plugin>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <Artifactid>Maven-resources-plugin</Artifactid>                <version>2.2</version>                <Configuration>                    <encoding>UTF-8</encoding>                </Configuration>            </plugin>        </Plugins>    </Build>

Some jar packages are not mavencenter when MAVEN is packaged. The relevant local jar package needs to be introduced in the POM, then the relevant depency should be changed as follows

 <Dependency>        <groupId>Org.wltea.ik-analyzer</groupId>        <Artifactid>Ik-analyzer</Artifactid>        <version>3.2.8</version>        <Scope>System</Scope>        <Systempath>${project.basedir}/lib/ik-analyzer-3.2.8.jar</Systempath>    </Dependency>

For the war package system, sometimes you need to hit the jar package into the relevant war package, you can use plugin, by default, all the jar files under Lib are packaged under Web-inf/lib. Of course, you can also pack other documents, such as xml,properties and so on. The relevant plugin are as follows:

 <plugin>            <groupId>Org.apache.maven.plugins</groupId>            <Artifactid>Maven-war-plugin</Artifactid>            <version>2.3</version>            <Configuration>                <Warname>${project.artifactid}</Warname>                <webresources>                    <Resource>                        <Directory>lib/</Directory>                        <TargetPath>Web-inf/lib</TargetPath>                        <includes>                            <include>**/*.jar</include>                        </includes>                    </Resource>                </webresources>            </Configuration>        </plugin>

If it's lib or its own package,

<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>trilead-ssh2</artifactId>
<version>build212-hudson-6</version>
</dependency>

Add dependency packages and join local dependency packages when MAVEN is packaged

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.