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

maven依赖本地非repository中的jar包-依赖jar包放在WEB-INF/lib等目录下的情况客户端编译出错的处理 maven找不到符号

阅读更多

 

 

总括:

 

web项目有web-inf/lib下的jar包需要引用在eclipse中可以build path加web app libaries ,

或者更通用的是在maven中不以本地库/私服依赖,而是直接引用硬盘上的jar---绝对地址

或者先把jar打包到本地库然后依赖

或者直接加lib

 

---绝对地址引用

 

<dependency> 

    <groupId>org.apache</groupId> 

    <artifactId>test</artifactId> 

    <version>1.0</version> 

    <scope>system</scope> 

    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/paypal_base.jar</systemPath> 

 </dependency>

 

<dependency>

<groupId>com.sf</groupId>

<artifactId>zxingcode</artifactId>

<version>0.0.1</version>

<scope>system</scope>

<systemPath>D:/软件/mysteel-code/zxingcode/0.0.1-SNAPSHOT/zxingcode-0.0.1-SNAPSHOT.jar</systemPath>

</dependency>

 

 

 

具体实示例:

 

 

 

MAVEN 
  今天在使用maven编译打包一个web应用的时候,碰到一个问题: 
  项目在开发是引入了依赖jar包,放在了WEB-INF/lib目录下,并通过buildpath中将web libariary导入。
在eclipse中开发没有问题,但是使用maven编译插件开始便宜总是报找不到WEB-INF/lib这个jar包中的类。 
显然实在编译的时候WEB-INF/lib并没有配置到maven-complier-plugin插件src目录中去, 
于是将这个目录添加进去,还是不好使。无赖,先把这个jar包安装到本地库中,然后添加dependency。 

后来google了下,发现maven提供了scope为system的依赖,文档的原文如下: 
system 
This scope is similar to provided except that you have to provide the JAR which contains it explicitly. 
The artifact is always available and is not looked up in a repository. 

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

复制代码
1 <dependency> 
2    <groupId>org.apache</groupId> 
3    <artifactId>test</artifactId> 
4    <version>1.0</version> 
5    <scope>system</scope> 
6    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/paypal_base.jar</systemPath> 
7 </dependency>
复制代码

或者

复制代码
1 <dependency>
2             <groupId>net.sourceforge.pinyin4j</groupId>
3             <artifactId>pinyin4j</artifactId>
4             <version>2.5.0</version>
5             <scope>system</scope>
6             <systemPath>${basedir}/src/main/webapp/lib/pinyin4j-2.5.0.jar</systemPath>
7         </dependency>
复制代码

 

 

!更好的方式是配置编译参数<compilerArguments>,添加extdirs将jar包相对路径添加到配置中,如下: 

复制代码
 1 <build>
 2          <plugins>
 3              <plugin>
 4                <artifactId>maven-compiler-plugin</artifactId>                                                               
 5                <configuration>                   
 6                     <source>1.6</source>                                       
 7                     <target>1.6</target>
 8                     <encoding>UTF-8</encoding> 
 9                     <compilerArguments>            
10                        <extdirs>src\main\webapp\WEB-INF\lib</extdirs> 
11                     </compilerArguments>
12                </configuration>
13              </plugin>
14          </plugins>
15      </build>
复制代码

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics