使用maven配置jar包时,有些jar包不在maven库中,故需添加本地jar包导maven项目中。
首先,需要在当前项目下,新建一个lib文件夹,存放本地jar包,如:
然后在maven的pom.xml中配置:
<!-- pdf itext -->
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>iText</artifactId>
<scope>system</scope>
<version>2.1.7</version>
<systemPath>${project.basedir}/lib/iText-2.1.7.jar</systemPath>
</dependency>
<dependency>
<groupId>com.itext</groupId>
<artifactId>itext-asian</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/lib/iTextAsian.jar</systemPath>
</dependency>
<dependency>
<groupId>com.itext</groupId>
<artifactId>iReport</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/lib/iReport.jar</systemPath>
</dependency>
<dependency>
<groupId>com.itext</groupId>
<artifactId>itext-rtf</artifactId>
<scope>system</scope>
<version>2.1.7</version>
<systemPath>${project.basedir}/lib/itext-rtf-2.1.7.jar</systemPath>
</dependency>
这里的groupId和artifactId以及version都是可以随便填写的,而scope必须填写为system,而systemPath填写当前jar包地址即可,其中${project.basedir}是maven的内置变量,指向pom.xml文件所在位置。
最后需要在maven打包的过程中加入本地的jar包,因为项目运行的时候需要用到,需要在pom.xml中配置:
<build>
<plugins>
<!-- 加载本地jar包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
参考博文:
1.Maven添加本地Jar包
2.Maven之——使用本地jar包并打包进war包里面的方法