maven-resources-plugin modified my file

maven-resources-plugin modified my file

Cause

In the process of analyzing user access logs through streaming tasks, the user’s remote IP needs to be parsed into corresponding provinces and cities. In this process, the ip library file needs to be loaded. The ip library files are unified in a certain directory of the project src/main/resources, but an error is reported during the loading process:

net.ipip.ipdb.InvalidDatabaseException: database file size error
  at net.ipip.ipdb.Reader.init(Reader.java:58)
  at net.ipip.ipdb.Reader.<init>(Reader.java:25)
  at net.ipip.ipdb.Reader.<init>(Reader.java:21)
  at net.ipip.ipdb.City.<init>(City.java:17)
  at com.xxx.xxx.util.IpDbUtils.<clinit>(IpDbUtils.java:24)

analysis

It can run if the IP library is copied to the classes directory. It can be ruled out that the problem is the IP library itself, so why can't it run after maven is packaged?

After many searches on the Internet, it turns out that the maven-resources-plugin is the cause of the problem. When maven is packaged, specific files are encoded and the files are not available.

solve

In the process of maven packaging project, the pom.xml configuration file can be configured to uniformly encode the project, but some files may not need to be re-encoded, such as: IP library files, certificate files, etc.; re-encoding may cause the files to be unusable.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <nonFilteredFileExtensions>
            <!-- 需要过滤那些后缀的文件 -->
            <nonFilteredFileExtension>ipdb</nonFilteredFileExtension>
            <nonFilteredFileExtension>xls</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

after that. . . Everything is OK!
maven-resources-plugin modified my file

Guess you like

Origin blog.51cto.com/15060469/2675537