简体   繁体   English

使用maven将第三方代码添加到带有缺陷的Eclipse项目中?

[英]Adding third party code to an eclipse project with depedencies using maven?

I'm trying to use elements of Google's Crawler Commons package to help with my own project in Eclipse but I'm having difficulties getting it to work due to missing dependencies. 我正在尝试使用Google的Crawler Commons软件包的元素来帮助我在Eclipse中创建自己的项目,但是由于缺少依赖项,我很难将其运行。 I'm new to Maven so I'm having some trouble understanding where I'm going wrong. 我是Maven的新手,所以在了解我要去哪里出错时遇到了一些麻烦。 Here are the steps I've gone through so far: 到目前为止,这是我已完成的步骤:

So after downloading the files here , I added the crawler-commons-0.5.jar to my Eclipse project build path. 因此,在此处下载文件后,我将crawler-commons-0.5.jar添加到了我的Eclipse项目构建路径。 When trying to use any of the classes, such as RobotUtils for example, the following error is raised: 尝试使用任何类(例如,RobotUtils)时,会出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at crawlercommons.robots.RobotUtils.(RobotUtils.java:36) at Main.Main.main(Main.java:8) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 2 more 线程“主要” java.lang.NoClassDefFoundError中的异常:Main.Main.main(Main.java:8)上的crawlercommons.robots.RobotUtils。(RobotUtils.java:36)上的org / slf4j / LoggerFactory .ClassNotFoundException:org.slf4j.LoggerFactory at java.net.URLClassLoader $ 1.run(URLClassLoader.java:372)at java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)at java.security.AccessController.doPrivileged(Native方法),位于java.net.URLClassLoader.findClass(URLClassLoader.java:360),位于sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308),位于java.lang.ClassLoader.loadClass(ClassLoader.java:424) java.lang.ClassLoader.loadClass(ClassLoader.java:357)...还有2个

So I downloaded the pom.xml for this project from here and dropped it into the root folder of where the Google Crawler Commons .jar is. 因此,我从此处下载了该项目的pom.xml,并将其放入了Google Crawler Commons .jar所在的根文件夹中。 I use the command mvn on it and it downloads some stuff and returns successfully. 我在上面使用了命令mvn ,它下载了一些东西并成功返回。 However, all it does is give me an additional folder called target with a couple of .jar files that have the correct name, but don't actually contain any of the classes I need. 但是,它所做的只是为我提供了一个名为target的附加文件夹,其中包含几个具有正确名称的.jar文件,但实际上不包含我需要的任何类。

So am I missing something here? 那我在这里想念什么吗? How do I get mvn to grab the org.slf4j.LoggerFactory code I need here? 如何获得mvn来获取此处需要的org.slf4j.LoggerFactory代码?

It's not quite clear if your project is a Maven project or a non-Maven vanilla Eclipse project. 您的项目是Maven项目还是非Maven香草Eclipse项目尚不清楚。

If it's a Maven project, then you need to add the correct slf4j dependency in the pom.xml file of your project . 如果是Maven项目,则需要在项目pom.xml文件中添加正确的slf4j依赖项。 Eclipse (its Maven plugin) will download the slf4j dependency automatically (or on the next clean build). Eclipse(其Maven插件)将自动下载slf4j依赖项(或在下一个全新构建中)。

If it's an Eclipse project, then you need to download the latest slf4j jar form their official website, and add it to the build path of your Eclipse project. 如果是Eclipse项目,则需要从其官方网站下载最新的slf4j jar,并将其添加到Eclipse项目的构建路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM