报错信息:filtering … \src\main\resources\lib\xx**.jar to \target\classes\lib\**xx.jar failed with MalformedInputException: Input length = 1 -> [Help 1]
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.3.1:resources (default-resources) on project 项目名: filtering 项目路径\src\main\resources\lib\bcpkix-jdk15on-1.70.jar to 项目路径\target\classes\lib\bcpkix-jdk15on-1.70.jar failed with MalformedInputException: Input length = 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <args> -rf :pig-upms-biz
该问题在项目使用Maven clean install的时候出现的,一开始想的是,是否与这个jar包 (bcpkix-jdk15on-1.70.jar) 有关系?但是在pom文件中把对应的依赖注释掉后,并没有解决问题。
看一下完整的报错解析,关键在于两个路径。发现是打包的时候,有一步操作需要把\src\main\resources\lib\下的jar包转移到target\classes\lib\之下,但是Input length说明导入的jar包数目不对。
原因分析:
因为项目需要用到一些外部jar包,一开始是使用如以下这种相对路径的方式引入,并把jar包放置在${project.basedir}/src/main/resources/lib/之下。
<dependency>
<groupId>org.zz</groupId>
<artifactId>gmhelper</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/gmhelper-1.0.0.jar</systemPath>
</dependency>
而项目的有一个打包插件,也就是报错的路径来源,就是转移jar包。
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<webResources>
<resource>
<directory>src/main/resources/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
<excludes>
<exclude>**/commons-io-2.5.jar</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
但是,后续又使用了如以下指令。这个指令会将Jar解析并放入本地仓库,这样的话使用插件再将jar包直接放到打包好的war包的WEB-INF/lib路径下,显示是不合适的。
mvn install:install-file -Dfile=相对路径/gmhelper-1.0.0.jar -DgroupId=org.zz
-DartifactId=gmhelper -Dversion=1.0.0 -Dpackaging=jar -Dmaven.repo.local={repository路径}
于是,如何解决?
插件可以不需要改动它,直接将${project.basedir}/src/main/resources/lib/下相关的jar包备份起来,并在该路径下删除掉,重新执行服务,若服务能够正常跑不报错,就执行maven clean install就可以正常打出包了。