JAR Files Required to Run dom\Counter.java

Q

What JAR files are required to run dom\Counter.java provided in the Apache Xerces package?

✍: FYIcenter

A

You can follow this toturial to find out what JAR files are required to run dom\Counter.java provided in the Apache Xerces package.

1. Create an XML file in the \fyicenter\xerces-2_11_0\ folder:

\fyicenter\xerces-2_11_0\samples>type User.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) 2017 FYIcenter.com -->
<User>
    <ID>101</ID>
    <BirthDate>1970-01-01+00:01</BirthDate>
    <Name>Frank Y. Ivy</Name>
    <Sex>  Male</Sex>
</User>

2. Compile the dom\Counter.java and run it. Execution fails with missing dom.wrappers.Xerces class:

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\javac 
   dom\Counter.java

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java 
   -cp . dom.Counter User.xml
error: Unable to instantiate parser (dom.wrappers.Xerces)

3. Run it again with xercesSamples.jar. Execution fails with missing org.apache.xerces.parsers.DOMParser class:

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java 
   -cp .;..\xercesSamples.jar dom.Counter User.xml

Exception in thread "main" java.lang.NoClassDefFoundError: 
   org/apache/xerces/parsers/DOMParser
   at dom.wrappers.Xerces.<init>(Unknown Source)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
   at java.lang.Class.newInstance(Class.java:442)
   at dom.Counter.main(Counter.java:372)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.DOMParser

4. Run it again with xercesImpl.jar added. Execution fails with missing org.w3c.dom.ElementTraversal class:

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java 
   -cp .;..\xercesSamples.jar;..\xercesImpl.jar dom.Counter User.xml

Exception in thread "main" java.lang.NoClassDefFoundError: 
   org/w3c/dom/ElementTraversal
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
   at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
   at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
   at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
   at dom.wrappers.Xerces.parse(Unknown Source)
   at dom.Counter.main(Counter.java:447)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal

4. Run it again with xml-apis.jar added. Execution goes well now.

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java 
   -cp .;..\xercesSamples.jar;..\xercesImpl.jar;..\xml-apis.jar 
   dom.Counter User.xml

User.xml: 162;9;0 ms (5 elems, 0 attrs, 0 spaces, 58 chars)

3 JAR files are needed to run dom.Counter: xercesSamples.jar, xercesImpl.jar, and xml-apis.jar.

 

Using Apache Xerces DOM Sample Programs

⇒⇒FAQ for Apache Xerces XML Parser

2017-12-04, 1055👍, 0💬