Reference file from inside a service
I am trying to implement maxmind's geoip2 and I am at the step where I need to initialize the DatabaseReader, my database file is currently stored at ui.content/src/main/content/jcr_root/conf/<my-app>/geoip/GeoLite2-City.mmdb and I am trying to access it like this:
public Location getLocation(InetAddress ip) throws GeoIp2Exception {
try {
File database = new File(this.path);
this.db = new DatabaseReader.Builder(database).build();
return db.city(ip).getLocation();
} catch (Exception e) {
throw new GeoIp2Exception(String.format("Could not determine data for %s", ip));
}
}
But I am getting the following error: java.io.FileNotFoundException: /conf/<my-app>/geoip/GeoLite2-Country.mmdb (No such file or directory)
I have verified the file is named correctly and that is shows up on the CRX so I am guessing I need something to actually access this.
