我使用maven添加到我的web项目geoip2但是在我尝试使用它时代码中,导入无效。我可以在maven依赖项中看到jar,但我无法使用它。我需要一些帮助。
答案 0 :(得分:0)
我知道这不是你问题的完整答案,但是评论的时间太长了。
我使用geoip2构建了一个示例项目。 POM如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>geoip</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>geoip</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>
Java代码:
package com.test;
import com.maxmind.geoip2.WebServiceClient;
import com.maxmind.geoip2.model.CountryResponse;
public class App {
public static void main(String[] args) throws Exception {
int userId = 0;
String licenseKey = "key";
WebServiceClient client = new WebServiceClient.Builder(userId, licenseKey).build();
CountryResponse response = client.country();
System.out.println(response.getCountry().getName());
}
}
我无法重现您的导入问题。它工作得很好。您可以在此处下载此测试:geoip2-test.zip
检查您是否可以从命令行构建项目:mvn clean install
如果是这样,那么可能是您的项目或IDE中的配置错误问题。
这是Eclipse?试试Maven -> Update Project
。有时,当我添加未立即检测到的新依赖项时,这对我有用。
答案 1 :(得分:0)
如果你使用intellij,那么首先关闭项目然后导入项目并使用自动导入为SBT项目。然后com.maxmind.geoip2被解析。