classpath error on running xerces java's dom.Writer() program
I understand this question couldn't be more beginner, but I am having a hard time to grasp why it is not working. The Apache Xerces-J comes with a binary distribution that I am sure many of us uses. Within it, there are all the library jars and sample jars dom.Writer
being one of it I am trying to run:
LICENSE NOTICE resolver.jar
LICENSE-SAX.html NOTICE.resolver.txt samples/
LICENSE.DOM-documentation.html NOTICE.serializer.txt serializer.jar
LICENSE.DOM-software.html Readme.html xercesImpl.jar
LICENSE.resolver.txt data/ xercesSamples.jar
LICENSE.serializer.txt docs/ xml-apis.jar
My understanding is that Java's default class path will search current direcotry first, so if I run
java dom.Writer
in that directory, then it should work ... shouldn't it? but no, and then I tried a bunch of different ways of giving the classpath, including java6's wildcard, nothing works.
so I know xercesSamples.jar
contains dom.Writer
, but I couldn't figure out how to run it .. silly, huh? Someone please enlighten me.
The error message is like:
Exception in thread "main" java.lang.NoClassDefFoundError: dom/Writer
Caused by: java.lang.ClassNotFoundException: dom.Writer
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessControl开发者_开发问答ler.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Thanks
Oliver
Include xercesSamples.jar in your classpath. Jars have to explicitly specified in classpath.
java -cp xercesSamples.jar:. dom.Writer
What @Kal said is the correct answer. however, the meta-answer, is why are you using xerces in the first place? any recent jvm comes with an xml DOM api implementation built in. unless you need some specific xerces feature, stick to the builtin implementations.
精彩评论