0

I need the jsoup parser library for a program I am writing. I'm testing one of the classes I have which should allow me to input something like java TestScanner "http://www.google.com/" and return a parsed string of words on the page (without the html tags). However when I try to run it I get the same error: NoClassDefFoundError: org/jsoup/Jsoup. I have the jar file in a folder, and added the library to DrJava with the correct path under preferences, etc. I'm not sure what the problem is and I can't find anything online to help. Thanks for any help and let me know if there's anything I need to clarify.

Edit: I'm not sure what where the path org/jsoup/Jsoup comes from, I don't have any path like that on my system.

Nick Borisenko
  • 494
  • 3
  • 18
  • `org/jsoup` is structure (in this case inside `jar`) which should hold `Jsoup` class, and folder or Jar with this location should be placed in your classpath. This error informs you that Java wasn't able to find any directory with such inner structure. So are you sure you added your Jar correctly? Maybe you added location of your Jar instead of Jar itself? Take a look at this instruction and make sure you did as it explains: https://www.seas.upenn.edu/~cis1xx/resources/java/jar/jarindrjava.html – Pshemo Nov 07 '15 at 22:52
  • That's the same website I used for instruction on how to add the jar file. I don't know if it would have any effect, but the version i used is 1.7.2 – Nick Borisenko Nov 07 '15 at 22:55
  • I don't have Dr Java installed so I can only suspect that you didn't add Jar but directory which contains that Jar to your classpath. Or maybe you add that Jar to your different project than you think... It is hard to tell without having this editor so I can't help you much :/ – Pshemo Nov 07 '15 at 23:13
  • I understand, I checked to make sure the jar file itself is in the path, and it is. Thank you for the help anyway! – Nick Borisenko Nov 07 '15 at 23:15
  • OK, I downloaded this editor, then in `Resource Locations` in `Extra Classpath` I `Add`ed `D:\downloads\jsoup-1.8.3.jar` and it works fine for me. I have no Idea what is wrong in your case... – Pshemo Nov 07 '15 at 23:26
  • Hm. I tried downloading the newest version of the jar file. Under `Extra ClassPath` I have the following path: `...\NBorisenko7\jsoup-1.8.3.jar`. I restarted the IDE as per the instruction on the website, and then tried running `java TestScanner "http://www.google.com"` but it still gave me the same error! I have no idea what's going on – Nick Borisenko Nov 07 '15 at 23:34
  • Wait, you are not running your code from Dr Java but from command line? – Pshemo Nov 07 '15 at 23:36
  • Yes, but the directory path in cmd is directing to the folder with my java files – Nick Borisenko Nov 07 '15 at 23:37
  • But classes from that Jar files are not there. And that is the problem. We are using editors/IDEs (which allow us to set up our project once and add to it all necessary jars) so we can avoid writing long console commands since they require passing informations about location of every class which we are going to use. So try with `java -cp location\of\that\jar YourClass yourArgument`. – Pshemo Nov 07 '15 at 23:39
  • Do I have to include the location of the file if the directory path already points to the folder that contains the jar file? I tried `java -cp jsoup-1.8.3 TestScanner "http://www.google.com/"` but it then tells me that it can't find or load the class I provide – Nick Borisenko Nov 07 '15 at 23:59
  • Is there a way for me to pass an argument to `args` in the main method of the class without using a command line? – Nick Borisenko Nov 08 '15 at 00:04

0 Answers0