0

enter image description here

enter image description here

classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry exported="true" kind="lib" path="lib/jsoup-1.7.2.jar"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: gSportsParser (wrong
name: gSportsParser/gSportsParser)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

which is due to java not being able to find the Jsoup jar. I have looked up this problem and I've tried editing the build path, putting the jsoup in the same directory as the .class and in a subdirectory of the directory of class (/lib) to no avail. How do I make Java realize jsoup is there?

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
Goigle
  • 138
  • 13
  • The class that your exception complains about is `gSportsParser`. Do you run your code from Eclipse or from the command prompt? – PM 77-1 Nov 14 '13 at 17:53
  • this might help http://stackoverflow.com/questions/7509295/noclassdeffounderror-wrong-name – Nishant Nov 14 '13 at 17:55
  • The code works fine in eclipse. I figured URLClassLoader was in Jsoup but I'm not sure.. gonna try what n1234 said n1234 your answer helped I know can execute the gSportsParser.gSportsParser (probably gonna rename that to be less redundant) but I now need to find out how to let it find the jsoup .jar... I am currently in C:\Users\James\Documents\FrankDMINER\bin using the command java -cp C:\Users\James\Documents\FrankDMINER\bin gSportsParser.gSportsParser where should I put jsoup's jar or how do I add it to the command? – Goigle Nov 14 '13 at 18:03
  • @PM77-1 it's command prompt. It now sees the gSportsParser but can't find the jsoup library, it crashes when it gets to that portion of code Alright so I extracted the jsoup.jar files and now it works, but it is easier for me to have the jar as a jar. I guess this works but if anyone can help me keep the jar and alter the command i'm using to include the jar that would be cool – Goigle Nov 14 '13 at 18:12
  • You jar(s) should be in your `CLASSPATH` (either environment variable or `-cp` JVM parameter. . – PM 77-1 Nov 14 '13 at 18:25

2 Answers2

0

In Eclipse (the same as using javac to compile and java or javaw to run), the build classpath is separate from the runtime classpath. Adding JARs to your build classpath does not necessarily add them to the runtime classpath of your program/app.

You didn't mention how you're running your app, but in Eclipse there is the concept of Launch Configurations that are used to configure the runtime for a program. A Launch Configuration is created when you do something like right-click on a project or class and choose Run As... You can also view and edit the launch configurations from the toolbar buttons for Run and Debug. The bottom line is that Launch Configurations have a classpath and it must included all the projects and libraries (JARs) that your code uses.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
0

You need to include the jar file in your classpath. If you use eclipse, after adding the jar file, you should have something like the illustration below

enter image description here

adoughdough
  • 107
  • 1
  • 4