PHP->JAVA项目一,maven包引入第三方jar包,避免执行mvn package的时候报jar包不存在

spring boot 项目引入第三方jar包:

1.在intellij idea导入

这个方法在用maven打包的时候会找不到依赖包,项目能再ide里面运行,不建议用这种方法

个人放置在项目文件下新建lib文件夹,${basedir}/lib

PHP->JAVA项目一,maven包引入第三方jar包,避免执行mvn package的时候报jar包不存在

PHP->JAVA项目一,maven包引入第三方jar包,避免执行mvn package的时候报jar包不存在

PHP->JAVA项目一,maven包引入第三方jar包,避免执行mvn package的时候报jar包不存在

 

2.dependency 本地jar包

    <dependency>
        <groupId>com.hope.cloud</groupId>  <!--自定义-->
        <artifactId>cloud</artifactId>    <!--自定义-->
        <version>1.0</version> <!--自定义-->
        <scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
        <systemPath>${basedir}/lib/cloud.jar</systemPath> <!--项目根目录下的lib文件夹下-->
    </dependency> 
 

 3.编译阶段指定外部lib

在pom.xml中下方配置

     <plugin>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>2.3.2</version>
     <configuration>
     <source>1.8</source>
     <target>1.8</target>
     <encoding>UTF-8</encoding>
     <compilerArguments>
     <extdirs>lib</extdirs><!--指定外部lib-->
     </compilerArguments>
     </configuration>
     </plugin>

 4.将外部jar打入本地maven仓库

这个个人觉得最爽

cmd进入放置jar包的文件夹

    mvn install:install-file -Dfile=jacod.jar -DgroupId=com.jacod -DartifactId=jacod -Dversion=1.0 -Dpackaging=jar

执行完成后,在pom.xml中引入依赖

    <dependency>
    <groupId>com.hope.cloud</groupId>
    <artifactId>cloud</artifactId>
    <version>1.0</version>
    </dependency>