`
kavy
  • 浏览: 866336 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

解决Maven中使用很多本地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>src\main\webapp\WEB-INF\lib</extdirs>

    </compilerArguments>

  </configuration>

</plugin>

 

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

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics