由於第三方jar不在遠程maven庫上,又要實現遠程服務器自動打包發布功能,當然遠程服務器本地倉庫也是沒有要引入的第三方的jar,所以需要把本地引入的jar使用本地引入的方式,生成war時,直接打到war里。
pom【<dependencies>】節點添加本地jar
<dependency> <groupId>com.xxx.xxx</groupId> <artifactId>xx-xx-api</artifactId> <version>1.0-SNAPSHOT</version> <scope>system</scope> <systemPath>${basedir}/lib/xx-xx-api-1.0-SNAPSHOT.jar</systemPath> </dependency>
pom【<build><plugins><build/><plugins/>】添加以下
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>compile</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory> <includeScope>system</includeScope> </configuration> </execution> </executions> </plugin>
scope說明:
總結來說: compile:默認的scope,運行期有效,需要打入包中。 provided:編譯期有效,運行期不需要提供,不會打入包中。 runtime:編譯不需要,在運行期有效,需要導入包中。(接口與實現分離) test:測試需要,不會打入包中。 system:非本地倉庫引入、存在系統的某個路徑下的jar。(一般不使用)