maven 資源過濾配置(resource下文件maven package后target中文件體積變化,文件損壞)

maven 資源過濾:讓 Maven 能解析資源文件中的標識符,替換其中的配置(例如: ${} )信息為實際的值

問題現(xiàn)象

maven 打包后,target下相應(yīng)的pdf文件異常,手動打開提示文件損壞,查看文件詳情發(fā)現(xiàn)文件大小變了

以下摘自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 src/main/resources (default) for the resources which are not filtered and another folder src/main/resources-filtered for the resources which are filtered.

也就是說二進制文件不能過濾,要排除需要打包的二進制文件。

解決方案

方案一:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

方案二:

<resources>
    <resource>
        <!--排除pdf,不打包到classpath下,自然就不會過濾--> 
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>**/*.pdf</exclude>
        </excludes>
    </resource>
    <resource>
        <!--將pdf打包到classpath下,但是不進行資源過濾--> 
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*.pdf</include>
        </includes>
    </resource>
</resources>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容