报错内容:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager at us.codecraft.webmagic.downloader.HttpClientDownloader.<init>(HttpClientDownloader.java:38) at us.codecraft.webmagic.Spider.initComponent(Spider.java:280) at us.codecraft.webmagic.Spider.run(Spider.java:305) at us.codecraft.webmagic.model.samples.QQMeishi.main(QQMeishi.java:23) Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.HttpClientConnectionManager at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 4 more Process finished with exit code 1
原因:
不详,菜鸟一个,对于Maven
还不熟练,在webmagic-parent/pom.xml
中明明已经写上了版本号。
解决方法:
在webmagic-core/pom.xml
中对httpclient
指定版本号,并更新。
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency>