来自http://blog.csdn.net/fireofjava/article/details/45271193。
有一些遗留项目,要转到maven管理,但又因为是多人分布式开发,不好建本地仓库,不得已只能把几个包放到了WEB-INF/lib下,但是通过通常的方法去依赖这些包,在maven install的时候是会报错的,说找不到这些包,所以要通过一些配置来处理。
有两种方式:
1. 通过scope指定为system
<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>
2. 通过maven插件里面配置
<build> <plugins> <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> </plugins> </build>
这样配置以后就OK了。
不过我还碰到一个奇怪的现象,我两个项目,有一个不按上面配置就报错,按上面的配置后就正常了。
而另一个项目,我把lib下面的依赖删除,maven的pom.xml里面的依赖删除,所有的java类都报错了,但是我跑maven install居然一直都成功,无解。
我自己的maven编译引入做备份
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <!--<compilerArguments> <extdirs>F:\</extdirs> </compilerArguments>--> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> <excludeTransitive>false</excludeTransitive> <includeScope>compile</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>${project.build.directory}</outputDirectory> <resources> <resource> <directory>src/main/resources/</directory> <includes> <include>config/*</include> <include>config/*/*</include> </includes> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <excludes> <exclude>config</exclude> <exclude>config/*</exclude> <exclude>config/*/*</exclude> </excludes> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <Class-Path>./</Class-Path> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build>