[jdom-interest] Re: jdom 1.0 XMLOutputter -- problems

Frances fdr58 at yahoo.com
Mon Apr 3 13:51:38 PDT 2006

Bradley S. Huffman wrote:
>>Exception in thread "main" java.lang.NoClassDefFoundError: 
>>I downloaded jdom this weekend, put jdom.jar and all other jars that 
>>come with the download in the classpath...  but get many errors when 
>>trying to compile stuff (deprecated methods (like addAttribute(), which 
>>I change to setAttribute() but still get errors..  errors that 
>>SAXBuilder and XMLOutputter can't be found.. I looked in jar, I looked 
>>in docs, these classes are there..) what is the problem pls, thank you...
> addAttribute?  Sounds like there's a very old jar in your classpath. Did you
> download from http://www.jdom.org/dist/binary either jdom-1.0.tar.gz or
> jdom-1.0.zip, and are you sure it's in your classpath?
> Brad
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
yes and yes....

downloaded just this weekend, downloaded jdom-1.0.zip...

ok, look at this small example, from 

import java.io.*;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.input.*;
import org.jdom.output.*;

public class PrettyPrinter {
    public static void main(String[] args) {
     //    Assume filename argument
     //    String filename = args[0];
	  String filename = "myFile";

         try {
             // Build the document with SAX and Xerces, no validation
             SAXBuilder builder = new SAXBuilder();
             // Create the document
             Document doc = builder.build(new File(filename));

             // Output the document, use standard formatter
             XMLOutputter fmt = new XMLOutputter();
             fmt.output(doc, System.out);
         } catch (Exception e) {

this compiles fine but when run it with just this command:

     java PrettyPrinter

get following error: Exception in thread "main" 
java.lang.NoClassDefFoundError: org/jdom/input/SAXBui
lder (I don't get this.. if this class cannot be found how come it 
compiled fine?  do you need to always indicate cp when running classes 
with third-party API's?  I don't have to do this w/Tomcat..)

if I run it like this:  java -cp jdom.jar;. PrettyPrinter

get this error:

java.io.FileNotFoundException: C:\Documents and Settings\fdelrio\My 
Documents\xslt\myFile (The system cannot find the file specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.connect(Unknown 
sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
         at java.net.URL.openStream(Unknown Source)
         at org.apache.crimson.parser.InputEntity.init(Unknown Source)
         at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
         at org.apache.crimson.parser.Parser2.parse(Unknown Source)
         at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:810)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:789)
         at PrettyPrinter.main(PrettyPrinter.java:20)

I would LOVE to have some code to just create a simple xml file with 
JDOM.. (still don't know if SAX or DOM is best...)  'parsing' means to 
READ an xml file, so if you're CREATING an xml file you don't need to 
parse right?  sorry if these questions sound stupid, am just beginning 
to learn all this stuff.. finally know diff betw. SAX and DOM... :)

thank you very much..


More information about the jdom-interest mailing list