【问题标题】:Java Trouble compiling maxmind geoip LookupService classJava 编译 maxmind geoip LookupService 类的问题
【发布时间】:2013-09-03 10:03:14
【问题描述】:

我想知道是否有人可以帮忙,因为我正在努力编译 maxmind.geoip.LookupService.java

我已经下载了 geoip-api-1.2.10.jar 以包含在 WEB-INF\lib 中,并且我已经在我的类路径中引用了它,但它就是无法编译。

我已经成功编译了以下内容,所以我有点不知所措:

com.maxmind.geoip.Country
com.maxmind.geoip.DatabaseInfo
com.maxmind.geoip.Location
com.maxmind.geoip.Region
com.maxmind.geoip.timeZone

似乎无法为 com.maxmind.geoip 找到一整套已编译的 java 类,任何帮助将不胜感激 :-)

【问题讨论】:

    标签: java class geoip maxmind


    【解决方案1】:

    我通过从http://dev.maxmind.com/geoip/legacy/downloadable/ 下载最新的 java 文件解决了这个问题,解压文件夹,然后打开命令提示符并输入以下内容:

    cd source/com/maxmind/geoip/
    javac *.java
    

    我正在使用 jdk1.6.0_34 并且所有类都编译没有错误。

    我将 com.maxmind.geoip 文件夹复制到 \WEB-INF\classes 并下载 geoip-api-1.2.10.jar 并将其放在 WEB-INF\lib 文件夹中。

    最后,我从http://dev.maxmind.com/geoip/legacy/geolite/ 下载了 GeoIP.dat 并将其放在 webapps 下一个名为 GeoIP 的新文件夹中,这样我的所有应用程序都可以使用它。

    下面的代码是从一个用户的IP地址中获取国家代码:

    import com.maxmind.geoip.*;
    import java.io.IOException;
    
    class CountryLookupTest {
        public static void main(String[] args) {
        try {
            String sep = System.getProperty("file.separator");
            String dir = "C:/Program Files/Apache Software Foundation/Tomcat 7.0/GeoIP";
            String dbfile = dir + sep + "GeoIP.dat"; 
    
            LookupService cl = new LookupService(dbfile,LookupService.GEOIP_MEMORY_CACHE);
    
            System.out.println(cl.getCountry("151.38.39.114").getCode());
            System.out.println(cl.getCountry("151.38.39.114").getName());
            System.out.println(cl.getCountry("12.25.205.51").getName());
            System.out.println(cl.getCountry("64.81.104.131").getName());
            System.out.println(cl.getCountry("200.21.225.82").getName());
    
            cl.close();
        }
        catch (IOException e) {
            System.out.println("IO Exception");
        }
        }
    }
    

    希望这对其他人有用。

    【讨论】:

      【解决方案2】:

      根据MaxMind dev site,API 可在Maven Central Repository 上使用。除非你下载了源包,否则你不需要编译任何东西。

      【讨论】:

      • 我应该提到,我没有使用 Mavern,但谢谢。
      【解决方案3】:

      你必须从这个链接下载一个名为geoIP-api的Jar文件到maven存储库,如果你还没有从这个geoIP2下载其他Jar文件,也不要忘记下载。来自geoIP.dat 的 DAT 文件。然后将文件从 project properties 添加到您的项目类路径,然后 libraries 最后 add Jar in 网豆

      现在使用这个代码:

          public String IpGeoLocation(String IP) {
              try {
                  String dbfile = "C:\\Users\\User Name \\Documents\\NetBeansProjects\\IP Tools\\resources/GeoIP.dat";
                  String location = "";
                  LookupService cl = new LookupService(dbfile, LookupService.GEOIP_MEMORY_CACHE);
                  location = cl.getCountry(IP).getName() + " " + cl.getCountry(IP).getCode();
                  cl.close();
                  return location;
              } catch (Exception e) {
                                 return "Error";
              }
          }
      

      我只能找到国家和国家代码!!

      【讨论】:

        猜你喜欢
        • 2015-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-27
        • 2018-10-14
        相关资源
        最近更新 更多