简体   繁体   中英

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. I'm new to Maven so I'm having some trouble understanding where I'm going wrong. 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. When trying to use any of the classes, such as RobotUtils for example, the following error is raised:

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

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. I use the command mvn on it and it downloads some stuff and returns successfully. 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.

So am I missing something here? How do I get mvn to grab the org.slf4j.LoggerFactory code I need here?

It's not quite clear if your project is a Maven project or a non-Maven vanilla Eclipse project.

If it's a Maven project, then you need to add the correct slf4j dependency in the pom.xml file of your project . Eclipse (its Maven plugin) will download the slf4j dependency automatically (or on the next clean build).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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