fop pom and module-info example

173 views Asked by At

I tried to locate an example of pom.xml and module-info.java to use fop in an embedded way with JPMS, namely Java-17, but could not find one.

E.g. my code:

        FopFactoryBuilder builder = new FopFactoryBuilder(basePath.toUri()).setPageHeight("297mm")
                .setPageWidth("210mm");
        FopFactory fopFactory = builder.build();
        out = new BufferedOutputStream(Files.newOutputStream(r));
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        Source src = new StreamSource(fo.toFile());
        Result res = new SAXResult(fop.getDefaultHandler());
        transformer.transform(src, res);

worked until fop 2.8 with

    <groupId>org.apache.xmlgraphics</groupId>
        <artifactId>fop</artifactId>
        <version>2.8</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>
        <exclusions>
    </dependency>

My module-info.java contains

requires Saxon.HE;
requires transitive org.slf4j;
requires java.prefs;
requires fop;
requires xmlgraphics.commons;
requires java.xml;

When upgrading to fop version 2.9 it misses the package org.apache.fop.apps. in compilation.

As I found that solution by trial-and-error, my question is a bit broader: How to embed fop in a JPMS project environment?

1

There are 1 answers

4
Naman On

Seemingly the classes(org.apache.fop.apps.*) you are looking for have been abstracted to fop-core, hence adding a requires directive for that as a module with version 2.9 shall get you going.

requires fop.core;

In fact referenced in a few documents and the mailing list threads --

The fop jar packages fop-util, fop-events, and fop-core, so you want either the all-in-one jar, or the other 3 jars, but not both.

So, it would be better to replace the requires fop with

requires fop.core;
requires fop.events;
requires fop.util;

But, the contributors needs to focus further to restructure the common packages to make all these three being used independently and combined by clients or else as shared by you compilation fails with :

java: the unnamed module reads package org.apache.fop.events from both fop.core and fop.events