美文网首页Java学习笔记SpringFrameworkJava 杂谈
小记配置 maven-assembly-plugin 误修改文件

小记配置 maven-assembly-plugin 误修改文件

作者: zvving | 来源:发表于2016-09-30 14:43 被阅读1114次

开发银联支付功能,本地功能全部跑通,部署到测试环境报证书签名错误。 进一步可以看到 FileInputStream 读文件时抛出异常:

java.io.IOException: DER length more than 4 bytes: 111

一番追溯,最终 diff file 才发现证书文件 51offer_unionpay.pfx 服务器上与本地并不一致,竟然是 maven 打包时出的问题。

项目 maven 打包时用的是 maven-assembly-plugin (留意 maven-resources-plugin 也存在类似的问题) 证书文件的打包配置如下:

<fileSet>
    <directory>src/main/resources/assets</directory>
    <outputDirectory>conf/META-INF/assets</outputDirectory>
    <includes>
        <include>**/*.*</include>
    </includes>
    <filtered>true</filtered>
</fileSet>

留意 <filtered>true</filtered> 这行配置。 这是 maven-assembly-plugin 从 pom 配置 properties 变量所用的配置,在证书文件这个场景并不需要。 maven-assembly-plugin 自作多情的过滤读写了证书文件,却没能正确处理文件自身的内容,导致了这个问题。

解决也很简单:改为<filtered>false</filtered> 提交重新发布,问题解决。

总结

  • 调试时留意报错细节,问题偶尔也会发生在你完全想不到的地方。
  • 配置也要力求精简,不要引入无关内容,拖泥带水只会给自己挖坑。

相关文章

网友评论

    本文标题:小记配置 maven-assembly-plugin 误修改文件

    本文链接:https://www.haomeiwen.com/subject/zealyttx.html