Maven 添加本地jar包

6 篇文章 0 订阅

使用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包里面的方法



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值