Classpath issue using XPathFactory - java

I keep getting the following exception on one of our live servers (the others running the same code seem ok):
java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/domwith the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:67)
I'm pretty sure that I have the Xalan and Saxon jars in the classpath (using IBM Java 1.5).
Do you have any Ideas what else could be wrong?
Edit:
That's the code that causes the Problem:
XPathFactory factory = XPathFactory.newInstance();
And it's running on a custom web server that's roughly based on the catalina engine.

You need to add the appropriate .jar in your classpath. In my case I used the Saxon-HE library.
There exists a bug in Saxon9 you maybe run into like me.
The bug has been corrected in version 9.5.1.5. So you may download the latest Saxon 9 HE.

Found the answer myself: The problem is the combination of using Java 5 and having an option
-Djava.endorsed.dirs
set to a directory that contained the xalan.jar.
Once removed everything works again.

Make sure you have the appropriate xml-apis.jar and xerces jars in your classpath for the version of xalan that you are using (check the release notes for what, exactly, you need).
Also make sure you don't have multiples as the xercesImpl.jar, xml-apis.jar and xalan.jar need to be in sync.

Related

Using org.eclipse.core.expressions: expressionLanguage.exsd could not be found

I am following this guide to incorporate an activation expression (from core expressions) into my own extension point. As the guide says, I have created my extension point schema as follows:
But as you can see, I get errors for the referenced elements. (Element 'xxx' is not defined).
Actually, when I switch to the definition tab and double-click in the schema URL in the Schema inclusions list, I get the error message schema:/org.eclipse.core.expressions/schema/expressionLanguage.exsd could not be found.
My first suspicion was that something might have changed here for Eclispe Kepler, but the docs say anything about it. And I imported the org.eclipse.core.expressions plug-in from the Plug-Ins view into my workspace temporarily and checked if the referenced schema is actually where it is supposed to be (which it is). So this seems to be ok.
My next suspicion was that this had something to do with my target platform, so I double-checked my target platform, but I don't see any issue here. It includes (among others) the features
org.eclipse.platform 4.3.2.v20140221-1852
org.eclipse.platform.source 4.3.2.v20140221-1852
org.eclipse.rcp 4.3.2.v20140221-1700
org.eclipse.rcp.source 4.3.2.v20140221-1700
and the Core Expressions bundles are there as well:
org.eclipse.core.expressions 3.4.501.v20131118-1915
org.eclipse.core.expressions.source 3.4.501.v20131118-1915
I am currently stuck. Any pointer what else I can check or how I can fix this is appreciated.
Does your plug-in file (org.eclipse.core.expression.xxx.jar) actually have the schema file?
Today I had same problem and found that the jar file doesn't have the schema file.
I downloaded source jar file which have the schema file (Actually I found the source jar file from : http://grepcode.com/snapshot/repository.grepcode.com/java/eclipse.org/4.2/org.eclipse.core/expressions/3.4.400) and put the schema file into my jar file and it solves the problem.
Good luck.
Ok, several chaotic attempts of
reloading the target platform
cleaning all projects
restarting Eclipse with -clean switch
seems to have done the trick. I am not sure what caused this, but now the error has vanished (and I hope it stays this way).

run jaxb1 code on jdk1.6

I have old jaxb1 code that I am trying to run on JDK1.6(u 31).
It compiled fine. When I try to run I get the error -
Error constructing QTIResultsProcessingV12:Input is not a well formed document: Provider com.sun.xml.bind.ContextFactory_1_0_1 not found
So I tried to google and found that I have to place jaxb1_impl.jar in classpath.
I did not find this jar in jdk lib , so I downloaded JAXB RI 2.1.10 and put the jaxb1_impl.jar in classpath. Yet I get the same error.
Migrating jaxb1->jaxb2 is something not desired at this point as this is a short term solution.

Play Framework: PDF 0.9 module not playing nicely with JavaAPIforKml

My Play project currently depends on Play's pdf module version 0.9 and JavaAPIforKml 2.2.0 (used to create objects representing kml files).
Previously I was using pdf module version 0.7 and everything was working fine.
Now that I have upgraded to version 0.9, all my tests for kml based classes now fail. The exception I get is this:
java.lang.ClassNotFoundException: org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl
at java.lang.ClassLoader.findClass(ClassLoader.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at
play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at javax.xml.datatype.FactoryFinder.getProviderClass(FactoryFinder.java:115)
at javax.xml.datatype.FactoryFinder.newInstance(FactoryFinder.java:146)
at javax.xml.datatype.FactoryFinder.findJarServiceProvider(FactoryFinder.java:298)
at javax.xml.datatype.FactoryFinder.find(FactoryFinder.java:223)
at javax.xml.datatype.DatatypeFactory.newInstance(DatatypeFactory.java:131)
at com.sun.xml.bind.DatatypeConverterImpl.<clinit>(DatatypeConverterImpl.java:833)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:287)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:286)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:285)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at de.micromata.opengis.kml.v_2_2_0.Kml.getJaxbContext(Kml.java:631)
at de.micromata.opengis.kml.v_2_2_0.Kml.createMarshaller(Kml.java:640)
at de.micromata.opengis.kml.v_2_2_0.Kml.marshal(Kml.java:682)
The part of the code that causes the exception is this:
de.micromata.opengis.kml.v_2_2_0.Kml kml = ...
kml.marshal(someByteArrayOutputStream); // This is the line that causes the exception
If I switch back to pdf module version 0.7, everything works again. Does anyone know what I could do to keep using pdf module version 0.9 and have the kml tests to continue to work?
In case it helps, the pdf module version 0.9 has these dependencies:
core-renderer.jar
itest-2.1.7.jar
jaxen-1.1.jar
jtidy-r938.jar
shani-parser-v1.4.17.jar
xml-apis.jar
yahp-internal.jar
yahp.jar
While the JavaApiForKml version 2.2.0 has these dependencies:
jaxb-impl 2.2
jaxb-xjc 2.2
xmlunit 1.2
I also struggled with the Play! PDF module breaking my (previously working) XML parsing.
Thanks for sharing your solution, it helped a lot! Though there is a more elegant way to achieve it.
As xerces lives on maven central, you should be able to add this to your dependencies.yml:
- xerces -> xercesImpl 2.10.0
That way you don't need to create a module for it, or worry about it being overwritten when you sync.
(I'm using 2.10.0, but you can swap that out for whichever version is most appropriate)
Cheers
This problem occurs because PDF module uses the jar file xml-apis.jar which adds org.allcolor.xml.parser.CDocumentBuilderFactory to the available DocumentBuilderFactory. Unfortunately, this document builder seems not handling very well some features, as the XPath evaluation.
When we add the Xerces library to the project, its DocumentBuilder supersedes the previous one and everything works fine. But this works by chance: it just happens that the Xerces DocumentBuilderFactory is the first one to be found.
In order to force the application to use the default DocumentBuilderFactory implementation I think that is preferable to define the corresponding system property, as defined in the javadoc.
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
Alternatively, we can create a new DocumentBuilderFactory instance explicitly indicating which implementation should be used:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null);
I've managed to get my build to work again however I don't particularly like the solution. Firstly, I download the xerces2 library from apache.
I put the jar into the lib directory and the build worked. This library never existed previously so I'm not sure how it worked before.
I then put the xerces jar in its own play "module" called xerces so that when running play deps --sync the xerces jar would not get wiped from the lib directory. After running the build using this technique the build failed again!
So after more playing around, I thought it may have something to do with the ordering of the jars. I renamed the xerces module I created to be called apache-xerces and re-ran the build and the build started working again!

Using Xalan in Eclipse plugin

I am facing problems with using xalan in eclipse plugin.
When I try to create factory instance by:
TransformerFactory tFactory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);
I get error:
javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
...
I have following libs in plugin classpath: xml-apis.jar, xercesImpl.jar, serializer.jar, xalan.jar
I even can't create class instance by:
c = Class.forName("org.apache.xalan.processor.TransformerFactoryImpl");
Object o = c.newInstance();
It returns ClassNotFoundException
But I can create instances of other classes from same jar and can run same code outside eclipse without problem.
Any idea?
Edit: TransformerFactory instantiating class (say "class1") is part of an external library added in the plugin classpath wheras the xalan.jar is also in plugin classpath. If I move this "class1" into plugin, it finds the provider and works fine.
Though I have seen this problem once, but I am not very sure how i solved it.
If you are using JDK 1.5 or above then try removing xml-apis.jar. It was needed for Java 1.4 to support XML.
Update 1
Ok. From your question I inferred that you are writing a eclipse plug-in. If yes, then have you added the above jars using plugin.xml->Runtime->classpath? If not try to do so. Eclipse plugin considers only its runtime->classpath entries
Update 2
To me it still appears as a classpath resolution issue. Though, its hard to say why its happening. For a try you can also check by changing the order of included jars in plugin.xml->Runtime->classpath.
Hope this will help.
PS: Since you are working on eclipse plug-in development therefore I would suggest you to go through this article Eclipse - a tale of two VMs and many classloaders.

Hibernate in Servlet causesNoClassDefFoundError: org/slf4j/LoggerFactory

I have a Java (6) application which uses Hibernate (V3.3.2) to read data from HSQLDB, which i build and debug/run with Eclipse (V3.5.1), and it works fine.
I then created a GWT (V1.7) Servlet web app, copied my hibernate classes into it, and added the same User Libraries dependencies. However when i run the servlet and try to access a URL which invokes my code i get this:
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at xxx.daoimpl.DAOSession.initialise(DAOSession.java:40)
where DAOSession.java:40 is :
AnnotationConfiguration config = new AnnotationConfiguration ();
Googling for this error suggests i am missing slf4j-api.jar from the classpath, however if i look at the command line for the Debug properties i can see this jar there:
C:\java\jsedk_6\jre\bin\javaw.exe
-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:54541
-Xmx512m -Dfile.encoding=Cp1252
-classpath
D:\dev\workspace\xxx\src;
D:\dev\workspace\xxx\resources;
D:\dev\workspace\xxx\war\WEB-INF\classes;
C:\java\eclipse\plugins\com.google.gwt.eclipse.sdkbundle.win32_1.7.1.v200909221731\gwt-windows-1.7.1\gwt-user.jar;
C:\java\eclipse\plugins\com.google.gwt.eclipse.sdkbundle.win32_1.7.1.v200909221731\gwt-windows-1.7.1\gwt-dev-windows.jar;
C:\java\hibernate-annotations-3.4.0.GA\hibernate-annotations.jar;
C:\java\hibernate-annotations-3.4.0.GA\lib\ejb3-persistence.jar;
C:\java\hibernate-annotations-3.4.0.GA\lib\hibernate-commons-annotations.jar;
C:\java\hibernate-distribution-3.3.2.GA\hibernate3.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\antlr-2.7.6.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\commons-collections-3.1.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\dom4j-1.6.1.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\javassist-3.9.0.GA.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\jta-1.1.jar;
C:\java\hibernate-validator-4.0.1.GA\hibernate-validator-4.0.1.GA.jar;
C:\java\hibernate-validator-4.0.1.GA\lib\validation-api-1.0.0.GA.jar;
C:\java\hibernate-validator-4.0.1.GA\lib\log4j-1.2.14.jar;
C:\java\hsqldb\lib\hsqldb.jar;
C:\java\restlet-jse-2.0m5\lib\org.restlet.jar;
C:\java\restlet-jee-2.0m5\lib\org.restlet.ext.servlet.jar;
C:\java\restlet-jse-2.0m5\lib\org.restlet.ext.xml.jar;
C:\java\slf4j-1.5.8\slf4j-api-1.5.8.jar;
C:\java\slf4j-1.5.8\slf4j-log4j12-1.5.8.jar
com.google.gwt.dev.HostedMode
...
If i open the jar i can see the LoggerFactory class in there.
Any idea why it isn't being found by the class loader?
Edit 1: If try to access org.slf4j.LoggerFactory from my code, Eclipse compiles it ok, but i get the same error at runtime.
Edit 2: If i add a Test class with a main which calls the same code and run it, it works. So this classpath problem seems specific to the Servlet.
thanks,
jon
It seems that copying the two slf4j jars to the war/WEB-INF/lib sub-project/dir fixed the problem. I'm not really sure why i should need to do this for these two jars and not for all the other Hibernate, Restlet etc jars that the project also uses, though i suppose for consistency i will do that anyway - i guess it will make deployment easier as well.
If someone can provide some sort of explanation as to why this worked and why exactly i need to do it i will select it as the "correct" answer, otherwise i'll select this one.
Can you please reconfirm that you have at least two slf4j.jar files in the classpath, the slf4j-api.jar and exactly one implementation, such as slf4j-jdk14.jar?
You must not have multiple sflj4-implementations in the classpath.
You have a runtime dependency issue so everything compiles fine but the dependency is in your jars. You need to visit the Hibernate site and look at the compatibility matrix and make sure you are matched up correctly then check the dependencies for annotations and core. You log4J jars look fine so it's definitely some quirk.
If it works in Eclipse then logically it's definitely some diff between the 2 runtimes (eclipse and non-eclipse), if the matrix checks out fine then see if you can factor out the commonalities in the 2 then work out the differences -- your answer should be in there.
I had a similar issue except I was using Tomcat and the NoClassDefFound error was on the juli logger. I fixed it by removing the Tomcat dependencies from my classpath when running in hosted mode because hosted mode embeds a Tomcat server that was conflicting. So I would see what happens if you remove some or all of the restlet jars from your classpath to see if they conflict.

Categories

Resources