环境
windows10
eclipse 4.7.0
jdk 1.8.0_181
Maven 3.6.2
tomcat 8.5
1. 并不需要标签<scope>system</scope> <systemPath>${basedir}/jar包相对路径下文件夹xxxx.jar</systemPath>,我本地打包使用了这两个标签反而不能将jar包引入war中,正常的写jar包的maven坐标即可,如下
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<!-- <scope>system</scope> <systemPath>${basedir}/lib_other/log4j-1.2.12.jar</systemPath> -->
</dependency>
<dependency>
<groupId>com.taobao</groupId>
<artifactId>taobao-sdk-java</artifactId>
<version>1</version>
<!-- <scope>system</scope> <systemPath>/${project.basedir}/lib_other/log4j-1.2.12.jar</systemPath> -->
</dependency>
</dependencies>
2.如果需要引入自己公司或者远程仓库查不到但本地有的jar包,可以使用
mvn install:install-file -Dfile=E:\xxxx\xxxx.jar -DgroupId=标签groupId之间的内容 -DartifactId=标签artifactId之间的内容 -Dversion=版本号 -Dpackaging=jar,将jar打到本地仓库在向war中引,如下图
3.引jar包到war包中
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>WebContent</directory>
</resource>
</webResources>
</configuration>
</plugin>
<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>
</plugins>
</pluginManagement>
</build>
如果使用标签plugin报错,需要在标签plugins外加一层标签pluginManagement,至于为什么自己百度,${project.build.directory}/${project.build.finalName}如果不明白也自行百度即可在,这就不做赘述了
4.成功后是这样的