【maven】Maven打包後為何檔案大小改變了

Love Lenka發表於2018-05-04

專案中使用了X.509證照,用Maven打包後,測試時報錯:

java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Invalid BER/DER data (too huge?)

 

查詢了好一會兒原因,才發現證照檔案確實變huge了。這是怎麼導致的呢,因為resource使用了filter, maven更改了檔案內容,解決方法如下:

 

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <encoding>UTF-8</encoding>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
            <nonFilteredFileExtension>crt</nonFilteredFileExtension>
            <nonFilteredFileExtension>cer</nonFilteredFileExtension>
            <nonFilteredFileExtension>key</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

  

 

以下摘自maven文件

 

Warning: Do not filter files with binary content like images! This will most likely result in corrupt output.

 

If you have both text files and binary files as resources it is recommended to have two separated folders. One folder  (default) for the resources which are not filtered and another folder  for the resources which are filtered.

相關文章