The Java keystore jks file is placed in the /src/main/resources directory. When it is compiled, it will automatically grow and become larger, causing java to read the keystore file abnormally and explode.
java.io.IOException:Invalid keystore format ...
exception.
This problem has been bothering me for a long time. It happened once in a previous project. At that time, because the project was very urgent, I put the jks file in the /src/main/java directory, so that it would not change. I felt very evil at that time. , hell
It happened again today, this time I forgot the last solution, googled the Internet for a long time, and finally got it from
http://stackoverflow.com/questions/19500458/maven-resource-binary-changes-file-size-after-build
and
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
I found the reason. In the /src/main/resources directory managed by maven, the placeholders in the file will be replaced. I don't know if there are many such characters in the jks file. Anyway, this is the effect.
The solution is to add restrictions to the pom.xml file that prohibit maven from arbitrarily claiming to modify resource files
- <build>
- <resources>
- <resource>
- <!-- Prevent JKS from being parsed incorrectly by maven -->
- <directory>src/main/resources</directory>
- <filtering>false</filtering>
- </resource>
- </resources>
- </build>
After cleaning it again
In the later time, I found that the above configuration was sometimes useless. I don't know if it was an environmental problem or something. Later, I googled a method.
http://stackoverflow.com/questions/19500458/maven-resource-binary-changes-file-size-after-build
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
</nonFilteredFileExtensions> </configuration> </plugin> </plugins></build>
This p12 is the meaning of the suffix. If you don't want him to modify any files, just add an entry in it.