The Java keystore jks file is placed in the /src/main/resources directory to report an error solution

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

 

[html]  view plain copy
 
 
  1. <build>  
  2.     <resources>  
  3.         <resource>  
  4.             <!-- Prevent JKS from being parsed incorrectly by maven -->  
  5.             <directory>src/main/resources</directory>  
  6.             <filtering>false</filtering>  
  7.         </resource>  
  8.     </resources>  
  9. </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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326507796&siteId=291194637