maven 如何解决因本地jar导致的编译错误

本文详细介绍了使用Maven的system依赖范围和maven-compiler-plugin的extdirs参数,解决本地非repository中的jar包在编译过程中出现的问题。通过配置system依赖,可以直接指定jar包路径,避免安装到本地库。同时,利用extdirs参数可以方便地添加大量历史遗留jar包路径,简化编译过程。

    如何解决Maven依赖本地非repository中的jar包,依赖jar包放在WEB-INF/lib等目录下的情况客户端编译出错的处理。http://www.mamicode.com/info-detail-169419.html

Maven提供了scope为system的依赖,文档的原文如下:

 

system
This scope is similar to provided except thatyou have to provide the JAR which contains it explicitly.
The artifact is always available and is notlooked up in a repository.

这样就可以添加dependency而不需要再将WEB-INF/lib目录下的jar包安装到本地库中了。

具体配置录下:

<dependency>
    <groupId>org.apache</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/test.jar</systemPath>
</dependency>

    如果只添加一个两个jar包,还比较方便,但是如果WEB-INF/lib/下面有几十个jar包,逐个添加就会显得很繁琐。最好是能方便配置 WEB-INF/lib/目录,让该目录下所有jar包都参与编译。这个配置在maven-compiler-plugin中。配置编译参 数<compilerArguments>,添加extdirs将jar包相对路径添加到配置中,如下: 

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <encoding>UTF-8</encoding>
    <compilerArguments>
      <extdirs>${basedir}\lib</extdirs>
    </compilerArguments>
  </configuration>
</plugin>

通过配置maven-compiler-plugin 的compilerArguments可以方便在使用Maven的时候,还大量使用以前使用Ant的大批WEB-INF/lib下面的历史遗留jar包。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值