maven项目中引入外部jar

1.打包jar至本地仓库

1.1 jar所在路径执行

mvn install:install-file -Dfile=xx.jar -DgroupId=cn.yang37.demo -DartifactId=xx -Dversion=1.0.0 -Dpackaging=jar

1.2 命令详细解释

mvn install:install-file 
-Dfile=xx.jar 
-DgroupId=cn.yang37.demo
-DartifactId=abc  //一般保持与上面的xx.jar中xx同名
-Dversion=1.0.0 
-Dpackaging=jar
        <dependency>
            <groupId>cn.yang37.demo</groupId>
            <artifactId>abc</artifactId>
            <version>1.0.0</version>
        </dependency>

2.pom文件引入

2.1 项目新建lib文件夹,放入jar包.

img

2.2 pom中引入jar

		<dependency>
          <groupId>dingding</groupId>
          <artifactId>dingding</artifactId>
          <version>2.8</version>
          <scope>system</scope>
          <systemPath>${project.basedir}/lib/taobao-sdk-java.jar</systemPath>
        </dependency>
  • groupId:自定义
  • artifactId:自定义
  • version:自定义
  • scope:必须是system
  • systemPath:jar包的路径(idea编写的时候会有提示的)

2.3 pom处理打包

<build>
   <resources>
    <resource>
      <directory>lib</directory>
      <targetPath>/BOOT-INF/lib/</targetPath>
      <includes>
        <include>**/*.jar</include>
      </includes>
    </resource>
   </resources>
 </build>

3.上传至maven中央仓库、maven私服

原文地址:https://www.cnblogs.com/yang37/p/15030078.html