Solved

Java SAX Xerces woes

Posted on 2006-11-12
3
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running JavaFX on JDeveloper 12C 1 116
Convert from a json string array to a Java object 3 80
running on tomcat not jboss eap 7.0 3 53
netbeans can not run self signed app 8 37
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

738 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