Maven pom文件配置非仓库的jar依赖(如:web app中的/WEB-INF/lib)

本文介绍如何在Maven项目中配置外部Jar包,包括通过maven-compiler-plugin指定编译目录、使用dependency标签配置系统路径、直接在IDE中添加外部Jar依赖以及将Jar安装到本地Maven仓库的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载地址:https://blog.youkuaiyun.com/yunfeng482/article/details/90232718

maven pom 配置 compile的web项目时指定/WEB-INF/lib 目录或者其他非maven仓库的jar作为额外的库目录,需要进行配置。

1、配置maven-compiler-plugin 中编译目录extdirs

<plugin>
	<artifactId>maven-compiler-plugin</artifactId>
    <configuration>
		<source>1.7</source>
        <target>1.7</target>
        <encoding>UTF-8</encoding>
        <compilerArguments>
            <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
        </compilerArguments>
    </configuration>
</plugin>

2、通过dependency进行配置jar的系统目录systemPath

<dependency>
	<groupId>com.go6d</groupId>
	<artifactId>animate</artifactId>
	<version>1.0.0</version>
	<scope>system</scope>
  <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/animate.jar</systemPath>
</dependency>

3、直接通过ide添加项目的外部jar依赖

在这里插入图片描述

4、通过把jar安装到本地maven仓库中再配置pom 依赖

1、把本地的jar报install到本地库

mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -Dversion=4.6.1 -Dpackaging=jar

2、然后配置maven配置pom.xml文件

<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-queryparser -->
<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-queryparser</artifactId>
    <version>4.6.1</version>
</dependency>

3、maven update项目,验证依赖是否添加到项目中

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值