3

Using fop and Java11 with Maven and Eclipse I can create PDF documents from an xsl-fo input.

But only if I start the program from within Eclipse.

My pom.xml advises Maven to copy all jar files used for dependencies, to a lib folder. Preparing to run from command line.

When I try to start the program from command line like

java -p target/rutil-0.0.1-SNAPSHOT.jar;target/lib -m eu.ngong.rutil/eu.ngong.rutil.App

I get this error:

Error occurred during initialization of boot layer java.lang.module.FindException: Unable to derive module descriptor for target\lib\batik-script-1.14.jar.

I can add exclusions to the fop dependency entry in pom.xml, but only to see the next failure message (same package in two modules) and so on.

How can I start my program from command line like Eclipse is doing?

My goal is to use fop in a nightly build batch run.

You may find an absolute minimal version of my program here.

Lii
  • 11,553
  • 8
  • 64
  • 88
ngong
  • 754
  • 1
  • 8
  • 23
  • 1
    Not solving your problem, but you can't use batik-script on the module path because the JAR declares a service that it doesn't contain itself and the module system fobids that - see [this issue](https://issues.apache.org/jira/browse/BATIK-1260). – Nicolai Parlog May 29 '21 at 06:31
  • Probably the quickest fix is not to use the module system for your application, you should be able to launch it from the class path with `-cp target/rutil-0.0.1-SNAPSHOT.jar;"target/lib/*"` instead of `-p ...`. – Nicolai Parlog May 29 '21 at 06:36
  • @NicolaiParlog moving everything to the classpath would mean getting rid of the `module-info`(not modularising one's app), right? In the hope of moving forward, I had [tried executing](https://stackoverflow.com/a/67743247/1746118) the linked project in the question with absolutely minimal dependencies required on the modulepath and still being able to execute with the rest of those in the classpath. I was able to see a successful execution for the shared sample. Any caveats you might find in the suggested approach? – Naman May 29 '21 at 10:10

2 Answers2

1

You can put all your non modularised artifacts on the classpath and not support deriving their module information. These would be primarily treated as an unnamed module.

java --module-path target/rutil-0.0.1-SNAPSHOT.jar;target/lib/fop-2.6.jar \
     --class-path target/lib \
     --module eu.ngong.rutil/eu.ngong.rutil.App

I have provided an explanation in this answer to the error that you are facing. The immediate way to solve it while using all other artifacts on modulepath as well could be hacking the jar to remove the entry from the MANIFEST.MF.

Naman
  • 27,789
  • 26
  • 218
  • 353
0

In Naman's solution FOP is placed on the class-path, instead on on the module path. This has some disadvantages.

You can also get FOP to work on the module-path of your application.

  • Use FOP 2.8, which doesn't have the error in the question.

  • Use the separate FOP artifacts, instead of the one that includes everything: fop-core, fop-events and fop-util. (This is the recommenced way anyway.)

  • In your module, declare requires fop-core.

  • Patch fop-core with the other modules: --patch-module fop.core=fop-events-2.8.jar;fop-util-2.8.jar.

    • Patching must be done both for compiling and running the application.
  • Start your application with --module and --module-path.

Done. :)

Lii
  • 11,553
  • 8
  • 64
  • 88