使用 Maven 命令 mvn package 打包时遇到了编译失败的问题。Maven 提示 compilation error : package does not exist jar 程序包不存在。经查,是在项目使用了非 Maven 仓库的 jar 包,即使用了本地 jar 包,导致 Maven 编译时找不到 jar 包。解决办法是配置 pom.xml ,将本地 jar 包的路径添加到其中,使得 Maven 在编译时能够识别并找到本地 jar 包。
pom.xml 中 maven-compiler-plugin 的配置参考如下。重点是 compilerArguments 元素的配置,将本地的 jar 包添加进来,只需在 compilerArguments 中添加一行语句。
<compilerArguments>
<extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
pom.xml 构建配置参考如下。
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>