Preface
Today I encountered a problem. We have an ip.dat binary file. Through the contents, we can parse the regional information of the IP. The local unit tests are OK. After deploying to the test environment, we found an error when parsing the IP. If you take the IP address printed out in the test environment, there is no problem in testing locally. Finally, I found that the ip.dat file size of the code base is only about 3.5M, while the ip.dat file size of the test environment is about 5M.
The question is: Why does the file become larger after ip.dat is packaged through maven? Since when maven is packaged, this file will be copied from the conf directory below src/main/resources/. I directly placed ip.dat in the conf directory instead of the resources directory, and found that the size was normal after packaging.
In other words, during the maven packaging process, the files in the src/main/resources/ directory are only larger. Because we enable resource filtering in the pom.
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource></resources>
Solution
The solution is very simple: just put ip.dat in the conf directory without participating in resource filtering. If you must place ip.dat in the resources directory, you can solve it through the following configuration.
<resources> <!--Exclude ip.dat, not packaged into classpath, naturally there will be no filtering --> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>ip.dat</exclude> </excludes> </resource> <!--Packing ip.dat into classpath, but not resource filtering --> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>ip.dat</include> </includes> </resource></resources>
When using maven for resource filtering, just filter files that need to be filtered, some binary files, such as https certificates, etc., do not participate in resource filtering, otherwise the file content will be corrupted after packaging.
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support to Wulin.com.