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

Frances fdr58 at yahoo.com
Tue Apr 4 08:22:16 PDT 2006


Edelson, Justin wrote:
>>not sure, the code creates the file here..
>>
>>   Document doc = builder.build(new File(filename));
> 
> 
> And if the file at the path specified in filename doesn't exist, then
> you'll get a FileNotFoundException. This has nothing to do with JDom.
> You could check this by doing something like:
> File f = new File(filename);
> if (f.exists()) {
>   Document doc = builder.build(f);
>   ....
> } else {
>   System.err.println("file at "+filename+" doesn't exist!!!");
> }
> 
> 
>>as for the code you posted, something interesting is happening: I can
> 
> get it to compile in Tomcat, but not outside Tomcat (just did a
> stand-alone with
> 
>>the code you posted, that's it..  in both cases have the class w/your
> 
> code (doXML.java) and all the jars that came w/jdom download in same
> directory,
> 
>>and compile thus:
> 
> 
>>javac -classpath
>>
> 
> jaxen-core.jar;jaxen-jdom.jar;jdom.jar;saxpath.jar;xalan.jar;xerces.jar;
> xml-apis.jar;.
> 
> 
>>works inside Tomcat, but not outside Tomcat..  why would this be.. 
> 
> 
> This isn't possible. Tomcat doesn't compile code, with the exception of
> JSPs. 

WHAT???  I compile servlets in Tomcat all the time, 'manually', i.e., in 
DOS shell.. (also I have another app, a chat applet, I've been working 
on it for a while now; an applet technically is a stand-alone class (I 
mean as opposed to servlet) I do exact same thing I mention in my 
previous post: I put applet and jars needed for it in same dir (at root 
of a webapp) and compile it in DOS shell (am on Windows 2000), works 
every time...  have been doing this for a while now... :)  so:  yes it 
IS possible.....  many thanks again to all for your help...



In any case, in my experience, the compiler has ever just not
> worked - it always gives some helpful error message (sometimes more
> helpful than others). Have you thought about using an IDE instead of
> using the command-line compiler? It might make things easier for you.
> 
> -----Original Message-----
> From: jdom-interest-bounces at jdom.org
> [mailto:jdom-interest-bounces at jdom.org] On Behalf Of Frances
> Sent: Tuesday, April 04, 2006 9:49 AM
> To: jdom-interest at jdom.org
> Subject: [jdom-interest] Re: jdom 1.0 XMLOutputter -- problems
> 
> Edelson, Justin wrote:
> 
>>Here's some basic document creation code:
>>	Document document = new Document();
>>	Element rootElement = new Element("root");
>>	document.setRootElement(rootElement);
>>	Element childElement = new Element("child");
>>	rootElement.addContent(childElement);
>>	childElement.setText("some text");
>>
>>Same code all on one line:
>>	Document doc2 = new Document().setRootElement(new 
>>Element("root").addContent(new Element("child").setText("some 
>>text")));
>>
>>As for your other issues, these really don't have anything to do with 
>>jdom. I suggest you read up on the importance of the classpath to 
>>figure out why your are getting a ClassNotFoundException. Comparing 
>>command-line Java with Tomcat isn't really a valid comparison as 
>>Tomcat is a container that uses custom classloaders based on a 
>>directory structure.
>>
>>As for your FileNotFoundException, any reason to think this isn't just
> 
> 
>>because this file doesn't exist?
> 
> 
> not sure, the code creates the file here..
> 
>     Document doc = builder.build(new File(filename));
> 
> as for the code you posted, something interesting is happening: I can
> get it to compile in Tomcat, but not outside Tomcat (just did a
> stand-alone with the code you posted, that's it..  in both cases have
> the class w/your code (doXML.java) and all the jars that came w/jdom
> download in same directory, and compile thus:
> 
> javac -classpath
> jaxen-core.jar;jaxen-jdom.jar;jdom.jar;saxpath.jar;xalan.jar;xerces.jar;
> xml-apis.jar;.
> 
> works inside Tomcat, but not outside Tomcat..  why would this be.. 
> thank you very much for your help..  Frances
> 
> 
> 
> 
>>Justin
>>
>>-----Original Message-----
>>From: jdom-interest-bounces at jdom.org
>>[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Frances
>>Sent: Monday, April 03, 2006 4:52 PM
>>To: jdom-interest at jdom.org
>>Subject: [jdom-interest] Re: jdom 1.0 XMLOutputter -- problems
>>
>>Bradley S. Huffman wrote:
>>
>>
>>>>Exception in thread "main" java.lang.NoClassDefFoundError: 
>>>>org/jdom/input/SAXBuilder..
>>>>
>>>>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.co
>>>m
>>>
>>
>>yes and yes....
>>
>>downloaded just this weekend, downloaded jdom-1.0.zip...
>>
>>ok, look at this small example, from
>>http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom-p2.html
>>
>>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) {
>>             e.printStackTrace();
>>         }
>>     }
>>}
>>
>>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
>>Source)
>>         at
>>sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
>>urce)
>>         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..
>>
>>Frances
>>
>>
>>
>>
>>
>>
>>
>>_______________________________________________
>>To control your jdom-interest membership:
>>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.co
>>m
>>
>>_______________________________________________
>>To control your jdom-interest membership:
>>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.co
>>m
>>
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 



More information about the jdom-interest mailing list