maven method of introducing local jar package

As maven package management tool, the benefits do not have to say

But in some cases, such as the need to introduce third-party packages, such as courier birds, Alipay, micro letters and other jar package (of course, it is possible to directly dependent maven)

If, after downloaded directly to a local, how to integrate it into their own maven project?

A lot of ways, here are four ways

1. uploaded to the central warehouse in maven

https://oss.sonatype.org/

Toss may also wish to make trouble, you can refer to  how to publish Jar package to Maven Central Repository (really too much trouble)

Advantages : may be introduced directly in pom.xml, no problem deploying packaging

Drawback : Upload complicated, cumbersome (create work orders, generate keys, etc.)

2. build maven PW

Manually upload in admin page, after the introduction of pom.xml

Upload ways to view  maven PW nexus upload and download third-party jar package

Advantages : download speed, maven project more suitable for polymerization, the internal applicable to deploy, the deployment package is no problem

Drawback : the first compared to some more trouble, but also occupied the local server resources

3. The traditional way

java SE routine

Lib new packet, then introducing (direct Eclipse build path) (idea some trouble: File → project structure → libraries → + jar package)

Advantages : simple, do not do additional configuration

Drawback : collaborative development, many people are required to do the same operation, communication is all about

4. pom file system properties of the scope

Advantages : the direct introduction after configuration, maven reImport to

Shortcoming : nothing disadvantage is that those who have to take some time to configure

Pre-conditions

Be introduced as taobao-sdk-java.jar

operating

  1. Custom directory, where the new lib folder in the root directory of the project will be put in jar

     

  2. pom.xml introduced
        <dependency>
          <groupId>dingding</groupId>
          <artifactId>dingding</artifactId>
          <version>2.8</version>
          <scope>system</scope>
          <systemPath>${project.basedir}/lib/taobao-sdk-java.jar</systemPath>
        </dependency>

note:

  • groupId: Custom
  • artifactId: Custom
  • version: Custom
  • scope: it must be a system
  • systemPath: Path jar package (the time of writing idea would prompt)

The manner described above, there is no problem in the development environment, and so the situation can not find what package does not exist

However, maven project deployment is generally packaged and released, so packed is the need for additional configuration (in the above-mentioned first two way do not need additional processing)

Package deal

When packing the following configuration needs to be done, the label needs to be introduced through the resource, the position build → resources → resource

 <build>
   <resources>
    <resource>
      <directory>lib</directory>
      <targetPath>/BOOT-INF/lib/</targetPath>
      <includes>
        <include>**/*.jar</include>
      </includes>
    </resource>
   </resources>
 </build>
  • directory: lib folder specified location, because it is relatively the project root, so you can write directly on the lib
  • targetPath: packaged into a folder location, write BOOT-INF / lib can, or WEB-INF / lib. [Slash (/) plus without all right, if it is, then write ./ mac]
  • includes: usually end in jar, wrote ** / * jar.

Complete pom.xml

        <dependency>
            <groupId>dingding</groupId>
            <artifactId>dingding</artifactId>
            <version>2.8</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/taobao-sdk-java-auto_1479188381469-20190628.jar</systemPath>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.11</version>
                <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                        <resource>
                            <directory>lib</directory>
                            <targetPath>/BOOT-INF/lib/</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </resources>
                    <imageTags>
                        <imageTag>${project.version}</imageTag>
                        <imageTag>latest</imageTag>
                    </imageTags>
                </configuration>
            </plugin>

ok, mvn package can be.

Guess you like

Origin www.cnblogs.com/chywx/p/11563318.html