Java在编译maxmind geoip LookupService类时遇到问题

Java在编译maxmind geoip LookupService类时遇到问题,java,class,geoip,maxmind,Java,Class,Geoip,Maxmind,我在努力编译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.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类集,如有任何帮助,将不胜感激:-)

根据,API可在上获得。除非下载了源程序包,否则不需要编译任何东西。

我通过从解包文件夹下载最新的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文件夹中

最后,我从下载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");
    }
    }
}

希望这对其他人有用。

你必须从这个链接下载一个名为Jar的Jar文件到maven repository,如果你还没有从go下载其他Jar文件,也不要忘记从go下载.DAT文件。然后将文件从project属性添加到项目类路径,然后从库添加文件,最后在netbeans中添加Jar

现在使用以下代码:

    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";
        }
    }

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

我应该提到,我没有使用Mavern,但谢谢你。