bd2kccd / py-causal

Other
204 stars 50 forks source link

Example code throws java errors #32

Closed camdencheek closed 7 years ago

camdencheek commented 7 years ago

On a fresh install, I get the exception JavaException: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created when I run py-causal-continuous-example.py

Details OS: Arch linux 64 bit

Java: openjdk version "1.8.0_141" OpenJDK Runtime Environment (build 1.8.0_141-b15) OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode)

Python version: 2.7.13

Stacktrace:

Exception in thread "Thread-0" javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created
        at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:311)
        at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)
        at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120)
        at java.util.prefs.XmlSupport.loadPrefsDoc(XmlSupport.java:241)
        at java.util.prefs.XmlSupport.importMap(XmlSupport.java:375)
        at java.util.prefs.FileSystemPreferences$6.run(FileSystemPreferences.java:575)
        at java.util.prefs.FileSystemPreferences$6.run(FileSystemPreferences.java:568)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.prefs.FileSystemPreferences.loadCache(FileSystemPreferences.java:567)
        at java.util.prefs.FileSystemPreferences.initCacheIfNecessary(FileSystemPreferences.java:550)
        at java.util.prefs.FileSystemPreferences.getSpi(FileSystemPreferences.java:527)
        at java.util.prefs.AbstractPreferences.get(AbstractPreferences.java:287)
        at java.util.prefs.AbstractPreferences.getBoolean(AbstractPreferences.java:500)
        at edu.cmu.tetrad.util.TetradLogger.<init>(TetradLogger.java:65)
        at edu.cmu.tetrad.util.TetradLogger.<clinit>(TetradLogger.java:108)
        at edu.cmu.tetrad.search.Fges.<init>(Fges.java:108)
Caused by: java.lang.RuntimeException: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created
        at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:308)
        ... 15 more
Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
        at java.util.ServiceLoader.fail(ServiceLoader.java:239)
        at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
        at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:294)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289)
        ... 15 more
Traceback (most recent call last):
  File "py-causal-fges-continuous-example.py", line 19, in <module>
    faithfulnessAssumed = True, verbose = True)
  File "/home/ccheek/.virtualenvs/rewrite/lib/python2.7/site-packages/pycausal/search.py", line 565, in __init__
    fges = javabridge.JClassWrapper('edu.cmu.tetrad.search.Fges')(score)
  File "/home/ccheek/.virtualenvs/rewrite/lib/python2.7/site-packages/javabridge/wrappers.py", line 311, in __call__
    result =  J.make_instance(self.cname, msig, *cargs)
  File "/home/ccheek/.virtualenvs/rewrite/lib/python2.7/site-packages/javabridge/jutil.py", line 1726, in make_instance
    raise JavaException(jexception)
javabridge.jutil.JavaException: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created
camdencheek commented 7 years ago

Turns out it was an issue with the version of xerces I was using. An updated jar file fixed the issue.

BnY commented 6 years ago

I have the same issue. I have no clue where to update xerces... I cannot find a file with xerces in the name at all below the JAVA_HOME. (No Java expert here) Do I just download it from apache and put it in the lib of java?

...

Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
    at java.util.ServiceLoader.fail(ServiceLoader.java:239)
    at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:294)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289)
    ... 16 more
Traceback (most recent call last):
  File "/home/user/workspace/ExampleModelling/CollectorModdeling_sec3.py", line 321, in <module>
    penaltyDiscount = 2, maxDegree = -1, faithfulnessAssumed = True, verbose = True)
  File "/home/user/software/anaconda3/lib/python3.6/site-packages/pycausal/search.py", line 235, in run
    self.tetradGraph = algorithm.search(tetradData, params)
  File "/home/user/software/anaconda3/lib/python3.6/site-packages/javabridge/wrappers.py", line 62, in <lambda>
    fn = lambda naame=name: lambda *args: self.__call(naame, *args)
  File "/home/user/software/anaconda3/lib/python3.6/site-packages/javabridge/wrappers.py", line 148, in __call
    result =  J.call(self.o, method_name, msig, *cargs)
  File "/home/user/software/anaconda3/lib/python3.6/site-packages/javabridge/jutil.py", line 887, in call
    result = fn(*nice_args)
  File "/home/user/software/anaconda3/lib/python3.6/site-packages/javabridge/jutil.py", line 854, in fn
    raise JavaException(x)
javabridge.jutil.JavaException: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created

EDIT: To answer my own question... Downloaded some JAR which looks like xerces from here And placed it next to the JARs of py-causal: /home/user/software/anaconda3/lib/python3.6/site-packages/pycausal/lib/ Seems to do the job...