Apache FOP: List of errors after adding Apache FOP Maven dependency

Viewed 1014

Now I'm working on a JDK-14 application which calls to a SOAP Web Service, and after receiving a XML result next it must call a method to generate a PDF document via Apache FOP library. Please note that I'm not using module-info.java for this project.

This is my current list of dependencies in Maven. All the project was running without problems. But after adding the two Apache FOP dependencies (see below), it is not possible to compile and run the application anymore.

<dependencies>
        <!-- Dependencies for XML marshaling and more -->
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>2.3.3</version>
        </dependency>
        <!-- Runtime -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.3</version>
            <scope>runtime</scope>
        </dependency>
        <!-- Dependencies for Web Service -->
        <dependency>
            <groupId>jakarta.xml.ws</groupId>
            <artifactId>jakarta.xml.ws-api</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>jakarta.jws</groupId>
            <artifactId>jakarta.jws-api</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>rt</artifactId>
            <version>2.3.3</version>
        </dependency>
        <!-- Dependencies for Apache PDF -->
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>xmlgraphics-commons</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>fop</artifactId>
            <version>2.5</version>
        </dependency>
        <!--Dependencies for QR Code-->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>3.4.0</version>
        </dependency>
</dependencies>

The error messages varies from:

import javax.xml.namespace.QName;
The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.Result;
The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.sax.SAXResult;
The package javax.xml.transform.sax is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.stream.StreamSource;
The package javax.xml.transform.stream is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.parsers.DocumentBuilderFactory;
The package javax.xml.parsers is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

I want to know how can I deal with this problem. Maybe using an exclusion tag inside the specific dependency in conflict?

PD. At the end it is possible to generate the PDF document, just by calling directly the Apache FOP jar from the command line.

java -jar fop.jar -r -xml <xml_path> -xsl <xsl_path> -param name1 value1 -param name2 value2 ... myPDF.pdf

But I want to know (1) if is still possible to configure via code. And (2) why this is happening now. The project was running with JDK-11 and JDK-13 before migration to JDK-14.

1 Answers

I'm not too certain quite why this problem occurs with recent JDK's.

With JDK-8, it's ok.

Of course, the javax.xml package is in the xml-apis dependency of apache-fop and in JDK-14, but that was also the case previously.

But anyway, the following dependency-exclusion solved the problem for me under JDK-14 using Eclipse-2020-06:

<!DOCTYPE xml>
<project
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.stackoverflow</groupId>
    <artifactId>apache.fop.jdk14.exclude.xml-apis</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.target>14</maven.compiler.target>
        <maven.compiler.source>14</maven.compiler.source>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>fop</artifactId>
            <version>2.5</version>
            <exclusions><exclusion><groupId>xml-apis</groupId><artifactId>*</artifactId></exclusion></exclusions>
        </dependency>
    </dependencies>
</project>
Related