如何在maven项目中导入第三方jar包
方式1:将外部jar打入本地maven仓库(推荐)
1.下载jar包到本地
2.打开cmd输入命令
格式:
mvn install:install-file
-Dfile=jar包的位置
-DgroupId=上面的groupId
-DartifactId=上面的artifactId
-Dversion=上面的version
-Dpackaging=jar
例如:mvn install:install-file -Dfile=F:\ideaProject\FFmpegNoMaven\lib\jave-1.0.2.jar -DgroupId=it.sauronsoftware -DartifactId=jave -Dversion=1.0.2 -Dpackaging=jar
备注: 如果发现自己的jar包没有打包在自己的maven仓库内,则找到cmd里显示的maven包安装路径。将整个目录复制到自己的maven仓库里
3.在javaweb项目的pom.xml里添加一下代码(注意要和上面命令行里安装的一致)
<!-- https://mvnrepository.com/artifact/it.sauronsoftware/jave -->
<dependency>
<groupId>it.sauronsoftware</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
</dependency>
方式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
<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>