Search code examples
javamavenbatikjava-platform-module-systemmodule-info

Circumvent old java meta-inf / services when using Java modules


I am trying to make a Java FX application showing an SVG-image using the Batik-library, but I'm having issues getting all the components properly imported.

After about 5 hours of searching and testing I have finally altered one of the dependencies' jars to remove old Java service (or whatever you call it) that predates the current module system. So the current work-around is to manually remove the "META-INF/services/org.apache.batik.script.InterpreterFactory"-file in "batik-script-1.13.jar".

Is there a proper way to do this? In my projects module-info, or through maven? Without having to manually alter the jar?

Thanks in advance! :)

If relevant: Mac OS, Java openjdk-14.0.2, Maven 3.6.3, VSCode 1.49.0


Solution

  • I was battling this for quite a while, before finally giving up JPMS and trying to circumvent the system by automating the JAR-alterations I had gotten working.

    By using a Maven plugin called Truezip I set up Maven to automatically unzip, alter and then rezip the dependency. Even though it's not the most elegant solution, it works, and I'm also using it on another dependency with a similar issue.

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>truezip-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <id>fix-batik-script</id>
                <goals>
                    <goal>remove</goal>
                </goals>
                <phase>process-resources</phase>
                <configuration>
                    <fileset>
                        <directory>${settings.localRepository}/org/apache/xmlgraphics/batik-script/1.13/batik-script-1.13.jar/META-INF/services</directory>
                        <includes>
                            <include>org.apache.batik.script.InterpreterFactory</include>
                        </includes>
                    </fileset>
                </configuration>
            </execution>
        </executions>
    </plugin>