Getting error “Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found” in unit test but not in main program

旧城冷巷雨未停 提交于 2019-12-21 10:51:40

问题


I am building an application in C# which uses com.gargoylesoftware.htmlunit.WebClient to access and retrieve information from webpages.

My application runs fine from the main project but when I try to build unit tests to test the project classes I get the following error:

FactoryConfigurationError
Message "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found"
Source  "IKVM.OpenJDK.XML.API"  string
StackTrace  "   at javax.xml.parsers.DocumentBuilderFactory.newInstance()
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration(Reader configurationReader)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration()
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration..ctor(BrowserVersion )
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(BrowserVersion browserVersion)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine..ctor(WebClient webClient)
at com.gargoylesoftware.htmlunit.WebClient.init(BrowserVersion , ProxyConfig )
at com.gargoylesoftware.htmlunit.WebClient..ctor(BrowserVersion browserVersion)
at com.gargoylesoftware.htmlunit.WebClient..ctor()
at GWT.HeadlessBrowser..ctor() in C:\\hg\\EXE\\GWT\\HeadlessBrowser.cs:line 57
at TestGWT.ProgramTest.TestLogInProcessForGWT() in C:\\hg\\TestGWT\\ProgramTest.cs:line 115"

Trying to create a HtmlUnit WebClient in the unit test class causes this error as well.

I have project references htmlunit-2.7, IKVM.OpenJDK.Core, and IKVM.OpenJDK.XML.API in both the main project and the project containing the unit test.

Do I need an additional project reference for the unit test to run? What might be causing this error?

The test class uses Microsoft.VisualStudio.TestTools.UnitTesting;


回答1:


I ran into the same issue just recently while testing the same library. I found that including a reference to IKVM.OpenJDK.XML.Parse.dll solved the issue.




回答2:


I hit a similar problem.

It seems the com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl class is not loaded and so the factory can not create it. Adding this line in before the call to the factory forces the assembly to load, and then the factory can see it and everything works as expected...

com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl s =   new  com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl();


来源:https://stackoverflow.com/questions/9001094/getting-error-provider-com-sun-org-apache-xerces-internal-jaxp-documentbuilderf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!