Solved

Java SAX Xerces woes

Posted on 2006-11-12
3
281 Views
Last Modified: 2013-11-23
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 build.sh. 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:

TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=screen
CLICOLOR=1
TERM_PROGRAM_VERSION=133
ANT_HOME=/usr/local/ant
LSCOLORS=ExFxCxDxBxegedabagacad
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin
STY=568.ttyp1.bobo
PWD=/Users/marshall/Desktop/xerces-2_8_1/samples/sax
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
XERCESJ2_HOME=/usr/local/xerces-2_8_1
CLASSPATH=:/usr/local/xerces-2_8_1/xercesImpl.jar:/usr/local/xerces-2_8_1/xercesSamples.jar:/usr/local/xerces-2_8_1/xercesSamples.jar:/usr/local/xerces-2_8_1/resolver.jar:/usr/local/xerces-2_8_1/xml-apis.jar:/usr/local/xerces-2_8_1/xercesImpl.jar:/usr/local/xerces-2_8_1/xercesSamples.jar:/usr/local/xerces-2_8_1/xercesSamples.jar:/usr/local/xerces-2_8_1/resolver.jar:/usr/local/xerces-2_8_1/xml-apis.jar
SECURITYSESSIONID=89a570
_=/usr/bin/env

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(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        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:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

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

      1 package javaxml2;
      2
      3 import java.io.IOException;
      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;
     16
     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.*;
     21
     22 public class SAXTreeViewer extends JFrame {
     23
     24     /** Default parser to use */
     25     private String vendorParserClass =
     26         "org.apache.xerces.parsers.SAXParser";
     27
     28     /** The base tree to render */
     29     private JTree jTree;
     30
     31     /** Tree model to use */
     32     DefaultTreeModel defaultTreeModel;
     33
     34     public SAXTreeViewer( ) {
     35         // Handle Swing setup
     36         super("SAX Tree Viewer");
     37         setSize(600, 450);
     38     }
     39


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.
0
Comment
Question by:bmarshallbri
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17926650
>>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
0
 

Author Comment

by:bmarshallbri
ID: 18155874
sorry for the delay in response. Just cleaning house.

That was it. Shining dummy moment.

Thanks

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18155922
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 77
HSSFWorkbook cannot be resolved error 10 51
Way to decrease size of apk file 9 46
Why my table column Id is not passed to java object? 4 28
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now