Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > dom4j NoClassDefFoundError

Reply
Thread Tools

dom4j NoClassDefFoundError

 
 
michael.miceli88@gmail.com
Guest
Posts: n/a
 
      06-09-2008
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());
     }
  }
}
and I also have
Code:
dom4j-1.6.1.jar
in the same directory
I compiled the app with
Code:
javac Foo.java -classpath
dom4j-1.6.1.jar
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
What am I doing wrong. If I unjar the dom4j-1.6.1.jar the
class labeled DocumentHelper is there.
Thanks,
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-10-2008
On Mon, 9 Jun 2008 09:07:34 -0700 (PDT), http://www.velocityreviews.com/forums/(E-Mail Removed)
wrote, quoted or indirectly quoted someone who said :

>by: java.lang.ClassNotFoundException:


This is my least favourite error message because it has dozens of
possible causes.
see
http://mindprod.com/jgloss/runerrorm...SDEFFOUNDERROR
--

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dom4j NoClassDefFoundError michael.miceli88@gmail.com Java 1 06-17-2008 12:29 AM
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory greg.knaddison@gmail.com Python 1 06-22-2004 10:58 PM
[Dom4j][Rules] What's wromng with this ? Cram TeXeD Java 1 02-02-2004 09:19 PM
[dom4j & Xerces] How to show validation errors? Stefan Siegl Java 2 07-17-2003 12:26 PM
How to compare to dom4j-Documents or How to read line by line from a dom4j-Document into a String? Wolfgang Java 0 07-09-2003 09:43 AM



Advertisments