我試圖在ColdFusion中使用MaxMind java庫。在ColdFusion中使用MaxMind java類
我開始在官方網站的MaxMind轉換此示例代碼:
// A File object pointing to your GeoIP2 or GeoLite2 database
File database = new File("/path/to/GeoIP2-City.mmdb");
// This creates the DatabaseReader object, which should be reused across
// lookups.
DatabaseReader reader = new DatabaseReader.Builder(database).build();
InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
// Replace "city" with the appropriate method for your database, e.g.,
// "country".
CityResponse response = reader.city(ipAddress);
Country country = response.getCountry();
我已經試過是:
var file = "pathto\maxmind\GeoLite2-City.mmdb";
var db = createObject("java","java.io.File").init(file);
var mm = createObject("java", "com.maxmind.geoip2.DatabaseReader")
.Builder(db)
.build();
dump(c);abort;
我得到這個錯誤:
Type: java.lang.NoSuchMethodException
Messages: No matching Method for Builder(java.io.File) found
for com.maxmind.geoip2.DatabaseReader
我做錯了嗎?
注意,'file'是CF中的保留字,因此您可能需要選擇不同的變量名稱以避免無意中發生的問題。 – Leigh
是的,我已經發布了代碼,僅作爲示例。我的真實代碼有點不同。謝謝 – Tropicalista