如何解決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包。