[英]The import com.maxmind.geoip2 cannot be resolved
我使用maven将其添加到我的Web项目geoip2中,但是在我尝试使用它的代码中,导入无法正常工作。 我可以在maven依赖项中看到jar,但是我不能使用它。 我需要协助。
我知道这不是您问题的完整答案,但是评论太久了。
我已经使用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
。 有时,当我添加未立即检测到的新依赖项时,这对我有用。
如果使用intellij,则首先关闭项目,然后导入项目,并对SBT项目使用自动导入。然后解析com.maxmind.geoip2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.