Skip to content

xml-apis imported into msg-rngconverter causes problems when using xml-apis #17

@steinarb

Description

@steinarb

I wanted to use xml-apis code in a unit test to verify that the results from msg-rngconverter after converting an XSD and I tried to do this:

    @Test
    void testConvertXsdFilesToRngFiles() throws Exception {
        XsdRngConverterMojo mojo = new XsdRngConverterMojo();
        mojo.xsdInputDirectory = new File(getClass().getClassLoader().getResource("xsd/xhtml1-strict.xsd").getFile()).getParent();
        mojo.rngOutputDirectory = testProperties.getProperty("testOutputDirectory");

        mojo.execute();

        var rngFiles = new File(mojo.rngOutputDirectory).listFiles(rngFileFilter);
        assertThat(rngFiles).hasSize(1);
        assertDoesNotThrow(() -> parseXmlFile(rngFiles[0])); // Verify generated file is XML file
    }

    private Document parseXmlFile(File file) throws Exception {
        var factory = DocumentBuilderFactory.newInstance();
        var builder = factory.newDocumentBuilder();
        return builder.parse(file);
    }

but that got the error:

The package javax.xml.parsers is accessible from more than one module: <unnamed>, java.xml

"mvn depedency:tree" told me that the msg-rngconverter was pulling in xml-apis (which conflicted with the xml-apis in the JDK itself.

So I tried excluding the xml-apis transitive dependency from msg-rngconverter

        <dependency>
            <groupId>net.java.dev.msv</groupId>
            <artifactId>msv-rngconverter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

and excluding xml-apis worked find for making the unit test compile, but XSD to RNG conversion failed with a ClassNotFoundException

java.lang.Error: com.sun.msv.datatype.xsd.DatatypeFactory$1
	at com.sun.msv.writer.relaxng.PatternWriter.serializeDataType(PatternWriter.java:324)
	at com.sun.msv.writer.relaxng.PatternWriter.onData(PatternWriter.java:248)
	at com.sun.msv.grammar.DataExp.visit(DataExp.java:94)
	at com.sun.msv.writer.relaxng.RELAXNGWriter$SmartPatternWriter.onRef(RELAXNGWriter.java:536)
	at com.sun.msv.grammar.ReferenceExp.visit(ReferenceExp.java:109)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:205)
	at com.sun.msv.writer.relaxng.RELAXNGWriter$SmartPatternWriter.onAttribute(RELAXNGWriter.java:562)
	at com.sun.msv.grammar.AttributeExp.visit(AttributeExp.java:94)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:205)
	at com.sun.msv.writer.relaxng.PatternWriter.onOptional(PatternWriter.java:132)
	at com.sun.msv.writer.relaxng.PatternWriter.onChoice(PatternWriter.java:143)
	at com.sun.msv.grammar.ChoiceExp.visit(ChoiceExp.java:48)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:203)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:202)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:202)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:202)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:202)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:202)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:202)
	at com.sun.msv.writer.relaxng.RELAXNGWriter$SmartPatternWriter.writeElement(RELAXNGWriter.java:577)
	at com.sun.msv.writer.relaxng.RELAXNGWriter$SmartPatternWriter.onElement(RELAXNGWriter.java:546)
	at com.sun.msv.grammar.ElementExp.visit(ElementExp.java:89)
	at com.sun.msv.writer.relaxng.RELAXNGWriter$SmartPatternWriter.onRef(RELAXNGWriter.java:536)
	at com.sun.msv.grammar.ReferenceExp.visit(ReferenceExp.java:109)
	at com.sun.msv.writer.relaxng.PatternWriter.visitBinExp(PatternWriter.java:162)
	at com.sun.msv.writer.relaxng.PatternWriter.onChoice(PatternWriter.java:147)
	at com.sun.msv.grammar.ChoiceExp.visit(ChoiceExp.java:48)
	at com.sun.msv.writer.relaxng.PatternWriter.visitUnary(PatternWriter.java:205)
	at com.sun.msv.writer.relaxng.RELAXNGWriter.writeIsland(RELAXNGWriter.java:359)
	at com.sun.msv.writer.relaxng.RELAXNGWriter.write(RELAXNGWriter.java:335)
	at com.sun.msv.writer.relaxng.RELAXNGWriter.write(RELAXNGWriter.java:187)
	at com.sun.msv.writer.relaxng.Driver.writeGrammar(Driver.java:88)
	at com.sun.msv.writer.relaxng.Driver.main(Driver.java:74)
	at no.priv.bang.maven.plugin.xsdrngconverter.XsdRngConverterMojo.convertXsdFilesToRngFiles(XsdRngConverterMojo.java:66)
	at no.priv.bang.maven.plugin.xsdrngconverter.XsdRngConverterMojo.execute(XsdRngConverterMojo.java:47)
	at no.priv.bang.maven.plugin.xsdrngconverter.XsdRngConverterMojoTest.testConvertXsdFilesToRngFiles(XsdRngConverterMojoTest.java:71)

Scratching my head trying to find a way to do both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions