generated certificate stops working when moved to resources folder

孤街醉人 提交于 2019-11-30 11:41:41

Check the content of the certificate file AFTER a build, when maven has copied to to target/classes/... Probably maven resource filtering, or something else in your build is modifying the file. Verify what ends up in the classes folder is EXACTLY the same as what is in the resources folder.

http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

chris

This is happening because maven's resource filtering is corrupting your p12 file.

We solved this by excluding p12 files from maven resource filtering with this in pom.xml:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>**/*.p12</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*.p12</include>
        </includes>
    </resource>
</resources>

Personally I don't like duplicating the excludes/includes section in the maven build and having two resource sections that must be kept in sync - so I prefer to use the maven resources plugin to configure the nonFilteredFileExtensions instead.

The resources section in the build section then simply is (plus any specific includes you might need):

<resources>
   <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
   </resource>
</resources>

Tell the maven-resources-plugin which files NOT to filter when including:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <configuration>
            <delimiters>
                <delimiter>@</delimiter>
            </delimiters>
            <nonFilteredFileExtensions>
                <nonFilteredFileExtension>p12</nonFilteredFileExtension>
                <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
                <nonFilteredFileExtension>pem</nonFilteredFileExtension>
            </nonFilteredFileExtensions>
        </configuration>
    </plugin>

See: http://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!