This API is for the GeoIP Legacy format (dat). To read the MaxMind DB format (mmdb) used by GeoIP2, please see our GeoIP2 Java API.
We recommend installing this package with Maven. To do this, add the dependency to your pom.xml:
<dependency>
<groupId>com.maxmind.geoip</groupId>
<artifactId>geoip-api</artifactId>
<version>1.2.14</version>
</dependency>
mvn clean install
mvn package
The jar file will be in the target
directory.
mvn test
The following options can be passed as the second parameter to the
LookupService
constructor.
GEOIP_STANDARD
- Read database from file system. Uses the least memory.GEOIP_MEMORY_CACHE
- Load database into memory. This provides faster performance but uses more memoryGEOIP_CHECK_CACHE
- Check for updated database. If database has been updated, reload file handle and/or memory cache.GEOIP_INDEX_CACHE
- Cache only the most frequently accessed index portion of the database, resulting in faster lookups than GEOIP_STANDARD, but less memory usage thanGEOIP_MEMORY_CACHE
. This is useful for larger databases such as GeoIP Legacy Organization and GeoIP Legacy City. Note: for GeoIP Legacy Country, Region and Netspeed databases,GEOIP_INDEX_CACHE
is equivalent toGEOIP_MEMORY_CACHE
.
These options may be combined. For example:
LookupService cl = new LookupService(dbfile,
LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE);
As of version 1.1.4 this API is thread safe.