Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to use JDeps with multi-jars in Java

1 min read

Java icon

If you have followed previous instalments, you will know we have used JDeps to create a multi-jar file version of our JPedal Java library. This allows it to support Java8 but offer support for Java modules if developers want to make use of this feature.

On Java 8, it works exactly as before. On Java 11 and above, it detects a module-info file and all the feature of project jigsaw work. We could have called this directory 9 and supported Java 9 and Java 10, but these were only short term releases and no-one should be using them.

JDeps generated a generic module-info file which has been edited to export just the correct API. There are lots of public classes used internally in JPedal, but they are no longer visible unless in the exported packages.

module com.idrsolutions.jpedal {
 
    requires java.desktop;
    requires java.logging;
 
    requires javafx.swing;
    requires javafx.controls;
 
    exports com.idrsolutions.image;
    exports com.idrsolutions.image.bmp;
    exports com.idrsolutions.image.jpeg;
    exports com.idrsolutions.image.jpeg2000;
    exports com.idrsolutions.image.jpeglossless;  
    exports com.idrsolutions.image.png;
    exports com.idrsolutions.image.scale;
    exports com.idrsolutions.image.tiff;
    exports com.idrsolutions.image.utility;
 
    exports org.jpedal;
    exports org.jpedal.examples;
    exports org.jpedal.examples.acroform;
    exports org.jpedal.examples.baseviewer;
    exports org.jpedal.examples.easyintegration;
    exports org.jpedal.examples.handlers;
    exports org.jpedal.examples.images;
    exports org.jpedal.examples.printing;
    exports org.jpedal.examples.text;
    exports org.jpedal.examples.viewer;
 
}

Now that we have a multijar, JDeps could potentially see different versions for different versions of Java. the JDeps tool solves this by elegantly failing with a sensible message

multijar warning message

Setting the –multi-release to different versions of Java shows some interesting results.

Java 10 (so no module file)

jdeps on Java10

Java 13 (module file present for Java11, Java12 and Java13)

JDeps with module-info file

This is really neat because it allows us to test our jar configuration under lots of different configurations!



Do you need to solve any of these problems in Java?

Convert PDF to HTML5
Convert PDF to HTML5
Convert PDF to SVG
Convert PDF to SVG
View Forms in the browser
View Forms in the browser
Java PDF Reader and Viewer
View PDF Documents
Convert PDF to image
Convert PDF to image
Extract Text from PDF
Extract Text from PDF
Read/Write images in Java
Read/Write images
Replace ImageIO
Replace ImageIO
Convert Image to PDF
Convert Image to PDF
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2020. All rights reserved.