添加到jar后,GeoLite2数据库会损坏 [英] GeoLite2 database gets corrupt when added to jar

查看:1602
本文介绍了添加到jar后,GeoLite2数据库会损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Java应用程序中包含一个Maxmind数据库。我使用的数据库是 GeoLite2-City.mmdb 的最新版本。

I'm trying to include one of the Maxmind databases in my Java application. The database I am using is the latest version of GeoLite2-City.mmdb.

当我删除数据库文件时进入项目( src / main / resources / GeoLite2-City.mmdb ),我运行项目,我可以通过 com使用数据库。 maxmind.geoip2.DatabaseReader 并执行IP地址的查找。

When I drop the database file into the project (src/main/resources/GeoLite2-City.mmdb) and I run the project I am able to use the database via com.maxmind.geoip2.DatabaseReader and perform lookups of IP addresses.

然而,一旦我编译项目并创建一个包含数据库的jar文件,我就是无法读取文件中的数据库,我得到异常:

However once I compile the project and create a jar file containing the database I am unable to read the database in the file, I get the exception:

com.maxmind.db.InvalidDatabaseException:找不到MaxMind数据库元数据此文件中的标记(< InputStream>)。这是一个有效的MaxMind数据库文件吗?

解压缩.jar文件并查看mmdb文件我可以看到文件的大小已经从38Mb变为59Mb,我猜这是抛出异常的原因。

Unzipping the .jar file and looking at the mmdb file I can see that the size of the file has changed from 38Mb to 59Mb, which I'm guessing is the reason for the exception being thrown.

有没有人知道在.jar中打包这个文件的方法这样它可用吗?我已经尝试将原始.gz文件添加到包中,然后解压缩然后加载数据库,但这也不起作用。

Does anyone know of a way of packaging this file in a .jar so that it is usable? I've tried adding the original .gz file into the package, then decompressing that and then loading the database but that doesn't work either.

谢谢

推荐答案

您没有提到如何创建JAR,但假设您使用的是Maven,则需要禁用二进制文件的资源过滤,例如:

You don't mention how you are creating the JAR, but assuming you are using Maven, you need to disable resource filtering for binary files, e.g.:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      ...
      <nonFilteredFileExtensions>
        <nonFilteredFileExtension>mmdb</nonFilteredFileExtension>
      </nonFilteredFileExtensions>
      ...
    </configuration>
  </plugin>

这篇关于添加到jar后,GeoLite2数据库会损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆