如何在使用JMapViewer时解决ClassNotFoundException

时间:2017-12-12 14:14:19

标签: java exception import jar

尝试运行代码时出现以下错误。

"C:\Program Files\Java\jdk1.8.0_151\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5\lib\idea_rt.jar=61473:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_151\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\rt.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\out\production\jmapviewer-2.4;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\json-20140107.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\commons-io-2.6.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\slf4j-api-1.7.25.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\commons-lang3-3.7.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\apacheds-all-1.5.4.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\apache-httpcomponents-httpcore.jar;C:\Users\Stefan\Desktop\jmapviewer-2.4\lib\WEB-INF\lib\httpclient-4.5.4.jar" org.openstreetmap.gui.jmapviewer.Demo
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/concurrent/Cancellable
    at se.kodapan.osm.services.nominatim.Nominatim.search(Nominatim.java:24)
    at org.openstreetmap.gui.jmapviewer.Demo.main(Demo.java:260)
Caused by: java.lang.ClassNotFoundException: org.apache.http.concurrent.Cancellable
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

Process finished with exit code 1

我尝试使用JMapViewer Demo和Nominatim来获取某个位置的坐标。 我按照一个类似异常的线程中的建议导入了HttpClient库(无论如何我都无法编译)

以下是我的导入列表(不确定是否有任何用途):

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.kodapan.osm.services.HttpService;

import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

看起来你需要Apache httpcore库

这可以在这里找到:

https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.4.8

另外,SLF4J需要一个用于日志输出的日志记录实现jar。 例如:

http://saltnlight5.blogspot.co.uk/2013/08/how-to-configure-slf4j-with-different.html