The local jar package is used in the MAVEN project _maven

Source: Internet
Author: User

There are two ways to use a local jar package in a MAVEN project:

1. Use System scope

  <dependencies>
    <dependency>
      <groupId>org.richard</groupId>
      <artifactid >my-jar</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
    </dependency>
  </ Dependencies>

Packages introduced by system scope will not be included when packaged with Jar-with-dependencies, and you can use resources to bring local packages into jar-with-dependencies

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId> <executions> <execution>
              <id>make-assembly</id> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <descri Ptorrefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descripto
          Rrefs> <finalName>xxx-jar-with-dependencies</finalName> </configuration>
      </execution> </executions> </plugin> </plugins> <resources>
        <resource> <targetPath>lib/</targetPath> <directory>lib/</directory>
 <includes>         <include>**/my-jar.jar</include> </includes> </resource> </resources > </build>

In the generated Xxx-jar-with-dependencies.jar, the Lib directory and the My-jar.jar are included, and can be found at execution time.

Sometimes this method can be effective, such as jdbcdriver in the statement class.forname ("xxx.") Driver ") will say that the class can not be found, in the following two ways.

2. Install Jar Pack into local repository

MVN Install:install-file-dfile=my-jar.jar-dgroupid=org.richard-dartifactid=my-jar-dversion=1.0-dpackaging=jar

3. Add in Project Repository, do not run the MVN install:install-file command when executing on a new machine

<repository>
    <id>in-project</id>
    <name>in project repo</name>
    <url >file://${project.basedir}/lib</url>
</repository>

<dependency>
    <groupid >org.richard</groupId>
    <artifactId>my-jar</artifactId>
    <version>1.0</ Version>
</dependency>

Your jar package and path must be in strict accordance with the format:

/groupid/artifactid/version/artifactid-verion.jar

In this case: Lib/org/richard/my-jar/1.0/my-jar-1.0.jar

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.