You are missing ws-commons-util-1.0.2.jar from $EXIST_HOME/lib/core.
I guess the documentation has become out of date. You should make sure you have included at least all of the libraries from $EXIST_HOME/lib/core.
Question
I am trying to access an eXist xml db using the embedded method, as described here.
That page has a list of jars needed for the classpath, and I have all of them there, but I keep getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/serialize/DOMSerializer
Here's what I have in my classpath; I'm using eclipse:
antlr-2.7.7.jar
commons-collections-3.2.1.jar
commons-logging-1.1.1.jar
commons-pool-1.6.jar
exist-modules.jar
exist-optional.jar
exist.jar
jta-1.1.jar
log4j-1.2.17.jar
pkg-repo.jar
quartz-2.1.6.jar
slf4j-api-1.7.2.jar
slf4j-log4j12-1.7.2.jar
sunxacml-1.2.jar
xmldb.jar
xmlrpc-client-3.1.3.jar
xmlrpc-common-3.1.3.jar
xmlrpc-server-3.1.3.jar
saxonhe-9.4.0.7.jar
serializer-2.7.1.jar
xalan-2.7.1.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
xml-resolver-1.2.jar
Here is the relevant code:
System.out.println("trying to call class.forname on " + DRIVER);
Class cl = Class.forName(DRIVER);
System.out.println("creating db instance");
Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
System.out.println("register database");
DatabaseManager.registerDatabase(database);
System.out.println("getting collection: " + URI + collectionName);
Collection collection = DatabaseManager.getCollection(URI + collectionName);
//collection.setProperty(OutputKeys.INDENT, "yes");
//System.out.println("getting resource");
//XMLResource xmlRes = (XMLResource)collection.getResource(resourceName);
and here is the console output including the error:
******************************************************
reading a doc from xml db
******************************************************
reading doc...
trying to call class.forname on org.exist.xmldb.DatabaseImpl
creating db instance
register database
getting collection: xmldb:exist://localhost:8080/exist/xmlrpc/db/test-journal
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/serialize/DOMSerializer
at org.apache.xmlrpc.serializer.NodeSerializer.<clinit>(NodeSerializer.java:30)
at org.apache.xmlrpc.common.TypeFactoryImpl.<clinit>(TypeFactoryImpl.java:88)
at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
at org.exist.xmldb.DatabaseImpl.getRpcClient(DatabaseImpl.java:324)
at org.exist.xmldb.DatabaseImpl.getRemoteCollection(DatabaseImpl.java:240)
at org.exist.xmldb.DatabaseImpl.getCollection(DatabaseImpl.java:164)
at org.exist.xmldb.DatabaseImpl.getCollection(DatabaseImpl.java:153)
at org.xmldb.api.DatabaseManager.getCollection(Unknown Source)
at org.xmldb.api.DatabaseManager.getCollection(Unknown Source)
at com.jasonwardenburg.codetest.exist.ExistDBFileReader.readDoc(ExistDBFileReader.java:48)
at com.jasonwardenburg.codetest.exist.ExistDBFileReader.main(ExistDBFileReader.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.ws.commons.serialize.DOMSerializer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
I went to the apache xml-rpc page, but most of the mirror sites are not functioning...anyone have any ideas as to the best way to get this working? thanks!
Solution
You are missing ws-commons-util-1.0.2.jar from $EXIST_HOME/lib/core.
I guess the documentation has become out of date. You should make sure you have included at least all of the libraries from $EXIST_HOME/lib/core.
OTHER TIPS
According to the dependencies tree for xmlrpc, you're missing ws-commons-util.jar, which is one of its runtime dependencies, if you're not using maven, you can download the jar from the central repository, here, then include it in your classpath. On the other hand, be wary! existDB docs are very specific about the fact that some of its features might not work if you don't include Xerces, Xalan and Saxon as endorsed libraries, since you're Java release might have the wrong versions. good luck.