Maven打包war时添加外部jar包
普通项目转maven项目后,发现Maven打包时并没有添加外部jar包,
所以,下面打包时将添加外部jar同maven中的jar包一起添加到编译后的文件当中,大致配置如下:
项目结构:
pom.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myService</groupId>
<artifactId>myService</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>xfj-push-service</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<!-- 解决WEB-INF/lib目录下的jar包无法用maven打包 -->
<compilerArguments>
<extdirs>${pom.basedir}/WebContent/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<!-- 配置web.xml文件的配置,解决缺少了一个必需的类;
error: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project myService: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.2:war failed: A required class was missing while executing org.apache.maven.plugins:maven-war-plugin:2.2:war: Lorg/apache/maven/archiver/MavenArchiveConfiguration; -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<!-- 指定web.xml的路径 -->
<webXml>WebContent\WEB-INF\web.xml</webXml>
<!-- 指定jsp、js、css的路径-->
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
重新运行打包后,成功了