3

I am trying to run a Java-11 application using fop from apache xmlgraphics.
The failure message

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules xml.apis and java.xml export package javax.xml.parsers to module junit

appears when I start the application with something like

java -p $modulepath -m module/package.App

My understanding of the message is: there are two required modules exporting the same package, which is not allowed. Right?

This is not the first time I got that message. Others I could repair by adding <exclusion/> with regarding groupId and artifactId to dependency specifications in pom.xml. So far

    <dependency>
        <groupId>org.apache.xmlgraphics</groupId>
        <artifactId>fop</artifactId>
        <version>2.6</version>
        <exclusions>
            <exclusion>
                <groupId>xalan</groupId>
                <artifactId>serializer</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xalan</groupId>
                <artifactId>xalan</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.xmlgraphics</groupId>
                <artifactId>batik-script</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.xmlgraphics</groupId>
                <artifactId>fop-util</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.xmlgraphics</groupId>
                <artifactId>fop-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.xmlgraphics</groupId>
                <artifactId>fop-events</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.xmlgraphics</groupId>
        <artifactId>xmlgraphics-commons</artifactId>
        <version>2.6</version>
    </dependency>

But with this message I do not know how to find out, which of my dependencies drags xml.apis and java.xml to my application.

Is adding <exclusion/> the right direction to go solving that problem?
If so, is there a way to find out recursively which of the applications dependencies exactly depends on java.xml and xml.apis?

Note: The Dependency Hierarchie of Eclipse/m2e does not show xml.apis or java.xml.

Full pom.xml

ngong
  • 754
  • 1
  • 8
  • 23
  • Which java 11 version are you using? Can you post your full pom.xml? I think adding exclusion could be the right solution, try to take a look at [this](https://stackoverflow.com/questions/56072355/migrating-from-jdk-8-to-open-jdk-11-missing-imports) – WoAiNii May 17 '21 at 20:08
  • Java 11.0.8+10 (are there significant differences to other versions?). Added the pom.xml in the question text above. It's a pom.xml for a module. The applying app is just a Hello-World that does not use any function of that module as the failure is in booting. – ngong May 18 '21 at 06:18
  • Are you sure you're running your app with the same jdk used to compile? Can you post a fully reproducible example? – WoAiNii May 18 '21 at 20:30
  • @WoAiNii: the Java11 is the same, for running and compiling. I could collect a sample using just fop and - if the failure does not appear again - add dependencies stepwise. Is that the only way to find out which of my dependencies rely on xml.apis? I guess my problem is similar to https://github.com/SpoonLabs/sorald/pull/342. Do you have a faster/easier way to explore dependencies than doing stepwise examples? – ngong May 19 '21 at 10:38
  • [Here](https://owncloud.august.de/index.php/s/cC5ZbXoSyzeWof6/download) you may find an example that just issues the problem: mvn install, target\classes\run – ngong May 19 '21 at 11:10
  • I get the code, maven install and run with java -jar rutil-0.0.1-SNAPSHOT.jar without a problem. Have you tried without xml-apis dependency or with the scope provided, since you're using java11? – WoAiNii May 20 '21 at 20:41
  • That is working for me as well. However, I cannot warrant that the modules folder lib is always near to the jar file. Therefore I'd like to start the App by ***java -p \rutil-0.0.1-SNAPSHOT.jar;\lib -m eu.ngong.rutil/eu.ngong.rutil.App*** and that is where my problem rises. (Pleas see my question above.) – ngong May 23 '21 at 10:46
  • I remove xml-api dependency, since it's within jdk 11, and it runs, even with java -p ... – WoAiNii May 23 '21 at 12:47
  • How did you "remove xml-api"? The pom.xml specifies no direct dependency on it. – ngong May 25 '21 at 14:22
  • In the pom.xml, within the above zip, there's `xml-apisxml-apis2.0.2`, I just remove it. – WoAiNii May 25 '21 at 18:08
  • Ok, WoAiNii - my mistake. The example does not tell my problem. Sorry. I revised the examle to a [new question](https://stackoverflow.com/questions/67742834/how-to-run-apache-fop-with-java-11). – ngong May 28 '21 at 16:57

0 Answers0