Java SAX Xerces woes

So admittedly I am at the beginning of my java learning curve. I have been working on trying to get a SAX XML parser put together and I can't get any of these classes to run to save my life. At this point I've backed off from trying to use any of my files and have been trying to run the SAX samples provided with Xerces. At least I feel a little less crazy since those don't run and produce the same errors as my files do.

I'm pretty sure this has something to do with my not having setup the environment properly or did not install Xerces correctly. In fact, in general I've been flailing through getting Xerces as far as I have. So some general knowledge about installing additional Java packages is sorely missing. Any notes would be appreciated.

Here's what I've got.

This is Mac OS X, so their own flavor of Net/Free BSDish-like Unix. Running the latest java 5. I installed ANT and used it to build Xerces. ANT and Xerces are both in /usr/local. ANT I compiled from source, worked fine, Xerces did not compile from source using either bash# ant all or ant jars or So I gave up completely on that and got the binary dist and unpacked in /usr/local and also unpacked the tools in /usr/local/xerces-2_8_1/tools

Here's my relative environment stuff:


and here's what bashrc actually looks like. I have tried this both in it's current state (pointing to jars explicitly) and just pointing to the xerces folder.

export XERCESJ2_HOME='/usr/local/xerces-2_8_1'
export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Home'
export ANT_HOME='/usr/local/ant'
export CLASSPATH="$CLASSPATH:$XERCESJ2_HOME/xercesImpl.jar:$XERCESJ2_HOME/xercesSamples.jar:$XERCESJ2_HOME/xercesSamples.jar:$XERCESJ2_HOME/resolver.jar:$XERCESJ2_HOME/xml-apis.jar"
export PATH=${PATH}:${ANT_HOME}/bin

So here's the error:

bobo:~/Desktop/xerces-2_8_1/samples/sax marshall$ java DocumentTracer
Exception in thread "main" java.lang.NoClassDefFoundError: DocumentTracer (wrong name: sax/DocumentTracer)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(
        at Method)
        at java.lang.ClassLoader.loadClass(
        at sun.misc.Launcher$AppClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(
        at java.lang.ClassLoader.loadClassInternal(

And finally, here some of the sample file from apache.

      1 package javaxml2;
      3 import;
      4 import java.util.HashMap;
      5 import java.util.Iterator;
      6 import java.util.Map;
      7 import org.xml.sax.Attributes;
      8 import org.xml.sax.ContentHandler;
      9 import org.xml.sax.ErrorHandler;
     10 import org.xml.sax.InputSource;
     11 import org.xml.sax.Locator;
     12 import org.xml.sax.SAXException;
     13 import org.xml.sax.SAXParseException;
     14 import org.xml.sax.XMLReader;
     15 import org.xml.sax.helpers.XMLReaderFactory;
     17 // This is an XML book - no need for explicit Swing imports
     18 import java.awt.*;
     19 import javax.swing.*;
     20 import javax.swing.tree.*;
     22 public class SAXTreeViewer extends JFrame {
     24     /** Default parser to use */
     25     private String vendorParserClass =
     26         "org.apache.xerces.parsers.SAXParser";
     28     /** The base tree to render */
     29     private JTree jTree;
     31     /** Tree model to use */
     32     DefaultTreeModel defaultTreeModel;
     34     public SAXTreeViewer( ) {
     35         // Handle Swing setup
     36         super("SAX Tree Viewer");
     37         setSize(600, 450);
     38     }

and here's the main class

     72     public static void main(String[] args) {
     73         try {
     74             if (args.length != 1) {
     75                 System.out.println(
     76                     "Usage: java javaxml2.SAXTreeViewer " +
     77                     "[XML Document URI]");
     78                 System.exit(0);
     79             }
     80             SAXTreeViewer viewer = new SAXTreeViewer( );
     81             viewer.init(args[0]);
     82             viewer.setVisible(true);
     83         } catch (Exception e) {
     84             e.printStackTrace( );
     85         }
     86     }
     87 }

Now, my error comes from me trying to run it like this

But the usage note in the main method suggests this, which errors with the included message.

bobo:~/Documents/Clients/echostar/scratch marshall$ java javaxml2.SAXTreeViewer test.xml
Exception in thread "main" java.lang.NoClassDefFoundError: javaxml2/SAXTreeViewer

So, I'm stumped. I think maybe I've been looking at this too much to where it's staring me in the face or there is something really weird and obscure that's going on.

please help and thank you very much.
Who is Participating?
CEHJConnect With a Mentor Commented:
>>Exception in thread "main" java.lang.NoClassDefFoundError: DocumentTracer (wrong name: sax/DocumentTracer)

You need to specify the correct package. Try

bobo:~/Desktop/xerces-2_8_1/samples/sax marshall$ java sax.DocumentTracer
bmarshallbriAuthor Commented:
sorry for the delay in response. Just cleaning house.

That was it. Shining dummy moment.


All Courses

From novice to tech pro — start learning today.