zoukankan      html  css  js  c++  java
  • Maven中使用本地jar包

      在Maven项目中使用本地jar包有如下几种方法:

     1、使用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>

    system scope引入的包,在使用jar-with-dependencies打包时将不会被包含,可以使用resources将本地包打进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>
                  <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                  </descriptorRefs>
                  <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>
    

     生成的xxx-jar-with-dependencies.jar中,将会包含lib目录以及my-jar.jar,并且能够被在执行的时候被找到。

     2、将jar包安装到本地repository中

     先下载jar包,下载后使用Maven进行本地安装,安装命令如下:

    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
    
    mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar
    
    mvn install:install-file -Dfile=D:XXX.jar -DgroupId=org.springframework -DartifactId=spring-context-support -Dversion=3.1.0.RELEASE -Dpackaging=jar
    

      安装实例参见:http://blog.csdn.net/u014079773/article/details/60773287

    参考:http://www.cnblogs.com/richard-jing/archive/2013/01/27/Maven_localjar.html

  • 相关阅读:
    Android应用性能测试
    Jmeter 中使用非GUI启动进行压力测试
    软件工程结对作业01
    第六周进度条
    求一维数组最大最大子数组和
    第五周进度条
    第四周进度条博客
    软件工程个人作业03
    第四周四则运算3 PSP表格
    poj 2096 概率dp
  • 原文地址:https://www.cnblogs.com/moonandstar08/p/7425690.html
Copyright © 2011-2022 走看看