We help IT Professionals succeed at work.

Java Class_Path and NoClassDefFoundError

Daniel Wilson
on
511 Views
Last Modified: 2013-11-23
I am working with an open-source project written in Java.  It has a complex directory structure ... like this:

-src
--org
---projectname
----subname
-classes
--org
---projectname

etc.

When I am in the classes folder and type java org.projectname.OneClassName I get:
Exception in thread "main" java.lang.NoClassDefFoundError: ExtractText (wrong name: org/pdfbox/ExtractText)
        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$000(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 java.lang.ClassLoader.loadClassInternal(Unknown Source)

If I descend into classes\org\projectname and type java OneClassName I get the same thing.

My Class_path variable is set to .;c:\SourceForge\PDFBox\External\junit.jar;C:\Program Files\Java\jre1.6.0_01\lib\ext\QTJava.zip -- in case that bears on this.

so ... what do I have to do to get java to find the file that's right in front of it?

Thanks!
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
>>You don't seem to have the PDF Box jar in your classpath - it should be

OK ... now I have built the jar using the ant script.

It was placed in lib, so in the lib folder I enter java org.PDFBox.PDFToImage and get
Exception in thread "main" java.lang.NoClassDefFoundError: org/PDFBox/PDFToImage

Now that I have changed into the lib folder, the "." part of my CLASS_PATH should mean I'm in the right place ... right?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> Exception in thread "main" java.lang.NoClassDefFoundError: org/PDFBox/PDFToImage

your pdbbox class were already in the classpath, you appear to have now broken your classpath even worse :)

problem originally seemed more that he pdfbox jars were n ot in the right directory structure (matching the package hierarchy). (Or you had another class called ExtractText)

If you do have the pdfbox jar then the easieat is to drop it in the ext filder and i'll be inclkuded automatically.

Author

Commented:
thanks to all of you.  Also to this site:
http://www.kevinboone.com/classpath.html

<quote>
Because a JAR is itself a directory, to include a JAR file in the class search path, the path must reference the JAR itself, not merely the directory that contains the JAR. This is a very common error. Suppose I have a JAR myclasses.jar in directory /myclasses. To have the Java compiler look for classes in this jar, we need to specify:

javac -classpath /myclasses/myclasses.jar ...

and not merely the directory myclasses.
</quote>
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.