Search code examples
groovysaxreflections

What driver are you expected to provide for Reflections.collect() to work from a Groovy script?


I have the following snippet of scratch code

import com.google.appengine.api.datastore.Entity
import org.reflections.Reflections

Reflections r = Reflections.collect()
Set<Class<?>> entities = r.getTypesAnnotatedWith(Entity.class)
print entities

that throws the following exception:

org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set?
    at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
    at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)

Googling for org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set? brings up questions, mostly about Android with link only answers or code based answers that do not actually address the issue of providing the correct system property value.

The same code works as Java code from the same IDE project.

So what do I have to supply to get this to work as a Groovy script?


Solution

  • I have this script in the src/test/groovy in my Maven project so I added.

    <dependency>
        <groupId>org.apache.servicemix.bundles</groupId>
        <artifactId>org.apache.servicemix.bundles.crimson</artifactId>
        <version>1.1.3_2</version>
        <scope>test</scope>
    </dependency>
    

    to my pom.xml

    And I added -Dorg.xml.sax.driver=org.apache.crimson.parser.XMLReaderImpl to the VM Options: in the Run/Debug Configuration for the script.

    This makes it work, but I would still like to know what I can used without having to add a dependency to get things in the test scope to run since things in the main scope work without this dependency.