Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2008

Tip: Looking for answers? Try searching our database.

dom4j NoClassDefFoundError

Thread view: 
michael.miceli88@gmail.com - 09 Jun 2008 17:07 GMT
I have simple application
[code]
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import java.io.FileWriter;
import java.io.IOException;

public class Foo {
   public Document createDocument() {
       Document document = DocumentHelper.createDocument();
       Element root = document.addElement( "root" );

       Element author1 = root.addElement( "author" )
           .addAttribute( "name", "James" )
           .addAttribute( "location", "UK" )
           .addText( "James Strachan" );

       Element author2 = root.addElement( "author" )
           .addAttribute( "name", "Bob" )
           .addAttribute( "location", "US" )
           .addText( "Bob McWhirter" );

       return document;
   }
  public static void main(String[] args){
    Foo ex = new Foo();
    try{
       FileWriter out = new FileWriter( "foo.xml" );
       Document document;
       document = ex.createDocument();
       document.write( out );
    }
    catch(IOException e){
       System.out.println("Unable to create file:" + e.getMessage());
    }
 }
}[/code]
and I also have [code]dom4j-1.6.1.jar[/code] in the same directory
I compiled the app with [code]javac Foo.java -classpath
dom4j-1.6.1.jar[/code] and got no errors, but when I run the code I
get this error[code]Exception in thread "main"
java.lang.NoClassDefFoundError: org/dom4j/DocumentHelper
       at Foo.createDocument(Foo.java:12)
       at Foo.main(Foo.java:32)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentHelper
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    ... 2 more
[/code]  What am I doing wrong.  If I unjar the dom4j-1.6.1.jar the
class labeled DocumentHelper is there.
Thanks,
Roedy Green - 10 Jun 2008 07:11 GMT
>by: java.lang.ClassNotFoundException:

This is my least favourite error message because it has dozens of
possible causes.
see
http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.