线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory while Using Crawler4j

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10430846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:01:04  来源:igfitidea点击:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory while Using Crawler4j

javaexceptioncrawler4j

提问by Raghavender Reddy

i am using Crawler4j Example code but i found that i got an exception.

我正在使用 Crawler4j 示例代码,但我发现我遇到了异常。

Here is my exception :

这是我的例外:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory
    at LocalDataCollectorController.main(LocalDataCollectorController.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.scheme.SchemeSocketFactory 

Here is my code :

这是我的代码:

    public static void main(String[] args) throws Exception {

            String root Folder = "D:\";
            int numberOfCrawlers = 5;
            System.out.println("numberOfCrawlers"+numberOfCrawlers);
            System.out.println(rootFolder);

          CrawlConfig config = new CrawlConfig();
            config.setCrawlStorageFolder(rootFolder);
            config.setMaxPagesToFetch(10);
            config.setPolitenessDelay(1000);

              PageFetcher pageFetcher = new PageFetcher(config);
           RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
            RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
            CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);

            controller.addSeed("http://www.ohloh.net/p/crawler4j");
            controller.start(LocalDataCollectorCrawler.class, numberOfCrawlers);

            List<Object> crawlersLocalData = controller.getCrawlersLocalData();
            long totalLinks = 0;
            long totalTextSize = 0;
            int totalProcessedPages = 0;
            for (Object localData : crawlersLocalData) {
                    CrawlStat stat = (CrawlStat) localData;
                    totalLinks += stat.getTotalLinks();
                    totalTextSize += stat.getTotalTextSize();
                    totalProcessedPages += stat.getTotalProcessedPages();
            }
           System.out.println("Aggregated Statistics:");
            System.out.println("   Processed Pages: " + totalProcessedPages);
            System.out.println("   Total Links found: " + totalLinks);
            System.out.println("   Total Text Size: " + totalTextSize);
    }

}

回答by Kai

Download the HttpClientand add it to your build path.

下载HttpClient并将其添加到您的构建路径中。

There is also a package which contains all crawler4j dependencies in the download section. You should use this to avoid further problems.

下载部分还有一个包含所有 crawler4j 依赖项的包。您应该使用它来避免进一步的问题。

回答by maksimov

The reason for NoClassDefFoundErroris always the same: you didn't supply the dependency class during runtime execution. In other words, when you ran your example, you didn't put HttpClient's JAR-file on the classpath. Do this and the problem will go away.

原因NoClassDefFoundError总是相同的:您没有在运行时执行期间提供依赖类。换句话说,当您运行示例时,您没有将 HttpClient 的 JAR 文件放在类路径上。这样做,问题就会消失。