エラー内容↓ Exception in thread "AWT-EventQueue-0" javax.xml.parsers.FactoryConfigurationError: Factory class is the wrong type at javax.xml.parsers.DocumentBuilderFactory.newInstan ce(DocumentBuilderFactory.java:115)
JAXP: The property is undefined. JAXP: found null in $java.home/jaxp.properties JAXP: no META- INF/services/javax.xml.xpath.XPathFactory file was found JAXP: attempting to use the platform default W3C DOM XPath lib JAXP: createInstance(com.sun.org.apache.xpath.internal.j axp.XPathFactoryImpl) JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactor yImpl from jar:file:/C:/Program%20Files/Java/jre7/lib/rt.jar! /com/sun/org/apache/xpath/internal/jaxp/XPathFacto ryImpl.class JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFacto ryImpl' was found for http://java.sun.com/jaxp/xpath/dom
XPathFactoryImplがCastできていない? どこを直せば・・・
評価
0
これは -Djaxp.debug=1 を付けて実行した際のログですよね、内容は XPathFactory xpathFactory = XPathFactory.newInstance(); みたいにXPathFactoryインスタンスを取得する際のログで、うまく生成されています。 エラーを起こすDocumentBuilderFactoryの方のログを表示してください。 私の環境では DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); の部分でエラーは発生せずに以下のようなログになります。 JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl using ClassLoader: null
評価
0
DocumentBuilderFactoryは、以下のとおりで同じです。 JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl using ClassLoader: null
追っかけていくと、以下ログの後にエラーが発生してい ます。
JAXP: no META- INF/services/javax.xml.xpath.XPathFactory file was found JAXP: attempting to use the platform default W3C DOM XPath lib JAXP: createInstance(com.sun.org.apache.xpath.internal.j axp.XPathFactoryImpl) JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactor yImpl from jar:file:/C:/Program%20Files/Java/jre7/lib/rt.jar! /com/sun/org/apache/xpath/internal/jaxp/XPathFacto ryImpl.class JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFacto ryImpl' was found for http://java.sun.com/jaxp/xpath/dom Exception in thread "AWT-EventQueue-0" javax.xml.parsers.FactoryConfigurationError: Factory class is the wrong type at javax.xml.parsers.DocumentBuilderFactory.newInstan ce(DocumentBuilderFactory.java:115)
javax.xml.xpath.XPathFactory←これが見つけられてい ない?
評価
0
ログを見る限りDocumentBuilderFactoryもXPathFactoryも正しく生成されているようですね。 試しに下のTestをコンパイルして java -Djaxp.debug=1 Test と実行するとどうなりますか?
public class Test { public static void main(String[] args) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); XPathFactory xpathFactory = XPathFactory.newInstance(); } }
私の環境では例外は発生せず以下のようなログが出力されます。 JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumntBuilderFactoryImpl JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocmentBuilderFactoryImpl using ClassLoader: null JAXP: using thread context class loader (sun.misc.Launcher$AppClassLoader@ff057) for search JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.om/jaxp/xpath/dom' JAXP: The property is undefined. JAXP: found null in $java.home/jaxp.properties JAXP: no META-INF/services/javax.xml.xpath.XPathFactory file was found JAXP: attempting to use the platform default W3C DOM XPath lib JAXP: createInstance(com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl) JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl from jar:fle:/C:/Program%20Files/Java/jre7/lib/rt.jar!/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.class JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl' was foud for http://java.sun.com/jaxp/xpath/dom
評価
0
新たなPJを立ち上げ、実行しました。エラーはでず、正 常終了しました。ログは、エラーが出たときのログと同 じ様子です。 JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl using ClassLoader: null JAXP: using thread context class loader (org.eclipse.core.runtime.internal.adaptor.Context Finder@61e76ee9) for search JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/ jaxp/xpath/dom' JAXP: The property is undefined. JAXP: found null in $java.home/jaxp.properties JAXP: no META- INF/services/javax.xml.xpath.XPathFactory file was found JAXP: attempting to use the platform default W3C DOM XPath lib JAXP: createInstance(com.sun.org.apache.xpath.internal.j axp.XPathFactoryImpl) JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactor yImpl from jar:file:/C:/Program%20Files/Java/jre7/lib/rt.jar! /com/sun/org/apache/xpath/internal/jaxp/XPathFacto ryImpl.class JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFacto ryImpl' was found for http://java.sun.com/jaxp/xpath/dom
JAXP: using thread context class loader (org.eclipse.core.runtime.internal.adaptor.Context Finder@59c10b51) for search JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/ jaxp/xpath/dom' JAXP: The property is undefined. JAXP: found null in $java.home/jaxp.properties JAXP: no META- INF/services/javax.xml.xpath.XPathFactory file was found JAXP: attempting to use the platform default W3C DOM XPath lib JAXP: createInstance(com.sun.org.apache.xpath.internal.j axp.XPathFactoryImpl) JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactor yImpl from jar:file:/C:/Program%20Files/Java/jre7/lib/rt.jar! /com/sun/org/apache/xpath/internal/jaxp/XPathFacto ryImpl.class JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFacto ryImpl' was found for http://java.sun.com/jaxp/xpath/dom
//成功するときは、以下処理が走るのですが、2回目 は、ここでエラーが発生します。
JAXP: using thread context class loader (org.eclipse.core.runtime.internal.adaptor.Context Finder@59c10b51) for search JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/ jaxp/xpath/dom' JAXP: The property is undefined. JAXP: found null in $java.home/jaxp.properties JAXP: no META- INF/services/javax.xml.xpath.XPathFactory file was found JAXP: attempting to use the platform default W3C DOM XPath lib JAXP: createInstance(com.sun.org.apache.xpath.internal.j axp.XPathFactoryImpl) JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactor yImpl from jar:file:/C:/Program%20Files/Java/jre7/lib/rt.jar! /com/sun/org/apache/xpath/internal/jaxp/XPathFacto ryImpl.class JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFacto ryImpl' was found for http://java.sun.com/jaxp/xpath/dom
評価
0
Exception in thread "AWT-EventQueue-0" javax.xml.parsers.FactoryConfigurationError: Factory class is the wrong type at javax.xml.parsers.DocumentBuilderFactory.newInstan ce(DocumentBuilderFactory.java:115)
またDocumentBuilderFactoryのソースを見ましたがnewInstanceの呼び出し上で Factory class is the wrong type というエラーメッセージは見あたりませんでした。 検索したところ古い実装では生成したオブジェクトをキャストする際にそのメッセージでFactoryConfigurationErrorを発生させるようです。 少なくともjava1.5以上ではClassCastExceptionがスローされるように変更されているようです。 またログの以下の部分を見ると JAXP: using thread context class loader (org.eclipse.core.runtime.internal.adaptor.ContextFinder@59c10b51) for search コンテキストクラスローダが何か設定されているようです。 私がEclipseでSwingアプリケーションのマウスイベント上でXPathFactory#newInstanceを呼び出してみたところ、ログは JAXP: using thread context class loader (sun.misc.Launcher$AppClassLoader@ff057f) for search となり、これは特にコンテキストクラスローダが設定されていないので通常使われるシステムクラスローダとなっています。 なので何かEclipseの設定がエラーの原因になっているような気がします。 そこで以下を確認してください。
Exception in thread "AWT-EventQueue-0" javax.xml.parsers.FactoryConfigurationError: Factory class null not found at javax.xml.parsers.ClassStuff.createFactory(ClassSt uff.java:141)