bmarshallbri
asked on
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 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/to ols
Here's my relative environment stuff:
TERM_PROGRAM=Apple_Termina l
SHELL=/bin/bash
TERM=screen
CLICOLOR=1
TERM_PROGRAM_VERSION=133
ANT_HOME=/usr/local/ant
LSCOLORS=ExFxCxDxBxegedaba gacad
PATH=/usr/local/bin:/bin:/ sbin:/usr/ bin:/usr/s bin:/usr/l ocal/mysql /bin
STY=568.ttyp1.bobo
PWD=/Users/marshall/Deskto p/xerces-2 _8_1/sampl es/sax
JAVA_HOME=/System/Library/ Frameworks /JavaVM.fr amework/Ho me
XERCESJ2_HOME=/usr/local/x erces-2_8_ 1
CLASSPATH=:/usr/local/xerc es-2_8_1/x ercesImpl. jar:/usr/l ocal/xerce s-2_8_1/xe rcesSample s.jar:/usr /local/xer ces-2_8_1/ xercesSamp les.jar:/u sr/local/x erces-2_8_ 1/resolver .jar:/usr/ local/xerc es-2_8_1/x ml-apis.ja r:/usr/loc al/xerces- 2_8_1/xerc esImpl.jar :/usr/loca l/xerces-2 _8_1/xerce sSamples.j ar:/usr/lo cal/xerces -2_8_1/xer cesSamples .jar:/usr/ local/xerc es-2_8_1/r esolver.ja r:/usr/loc al/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 /Framework s/JavaVM.f ramework/H ome'
export ANT_HOME='/usr/local/ant'
export CLASSPATH="$CLASSPATH:$XER CESJ2_HOME /xercesImp l.jar:$XER CESJ2_HOME /xercesSam ples.jar:$ XERCESJ2_H OME/xerces Samples.ja r:$XERCESJ 2_HOME/res olver.jar: $XERCESJ2_ HOME/xml-a pis.jar"
export PATH=${PATH}:${ANT_HOME}/b in
So here's the error:
bobo:~/Desktop/xerces-2_8_ 1/samples/ sax marshall$ java DocumentTracer
Exception in thread "main" java.lang.NoClassDefFoundE rror: DocumentTracer (wrong name: sax/DocumentTracer)
at java.lang.ClassLoader.defi neClass1(N ative Method)
at java.lang.ClassLoader.defi neClass(Cl assLoader. java:620)
at java.security.SecureClassL oader.defi neClass(Se cureClassL oader.java :124)
at java.net.URLClassLoader.de fineClass( URLClassLo ader.java: 260)
at java.net.URLClassLoader.ac cess$100(U RLClassLoa der.java:5 6)
at java.net.URLClassLoader$1. run(URLCla ssLoader.j ava:195)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(UR LClassLoad er.java:18 8)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:306)
at sun.misc.Launcher$AppClass Loader.loa dClass(Lau ncher.java :268)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:251)
at java.lang.ClassLoader.load ClassInter nal(ClassL oader.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.SAXParseExcept ion;
14 import org.xml.sax.XMLReader;
15 import org.xml.sax.helpers.XMLRea derFactory ;
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/e chostar/sc ratch marshall$ java javaxml2.SAXTreeViewer test.xml
Exception in thread "main" java.lang.NoClassDefFoundE rror: 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.
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/to
Here's my relative environment stuff:
TERM_PROGRAM=Apple_Termina
SHELL=/bin/bash
TERM=screen
CLICOLOR=1
TERM_PROGRAM_VERSION=133
ANT_HOME=/usr/local/ant
LSCOLORS=ExFxCxDxBxegedaba
PATH=/usr/local/bin:/bin:/
STY=568.ttyp1.bobo
PWD=/Users/marshall/Deskto
JAVA_HOME=/System/Library/
XERCESJ2_HOME=/usr/local/x
CLASSPATH=:/usr/local/xerc
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/
export JAVA_HOME='/System/Library
export ANT_HOME='/usr/local/ant'
export CLASSPATH="$CLASSPATH:$XER
export PATH=${PATH}:${ANT_HOME}/b
So here's the error:
bobo:~/Desktop/xerces-2_8_
Exception in thread "main" java.lang.NoClassDefFoundE
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
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.SAXParseExcept
14 import org.xml.sax.XMLReader;
15 import org.xml.sax.helpers.XMLRea
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
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/e
Exception in thread "main" java.lang.NoClassDefFoundE
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER
That was it. Shining dummy moment.
Thanks