Reputation: 41
Tried to use JLink to create a runtime image, however:
Error: automatic module cannot be used with JLink: graphviz.java
I'm using the following library which has only automatic modules.
Did some searches, and it seems that I can use ModiTect to generate module-info for the library and create a runtime image.
However, as I am new to modules I couldn't figure it out. I guess I would need a more in-depth explanation then what I could find on ModiTect's GitHub page.
my modules-info.java:
module elitonlais {
requires javafx.controls;
requires javafx.fxml;
requires graphviz.java;
opens elitonlais to javafx.fxml;
opens elitonlais.controller to javafx.fxml;
opens elitonlais.model to javafx.fxml;
exports elitonlais;
exports elitonlais.controller;
exports elitonlais.model;
}
My pom file:
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>elitonlais</groupId>
<artifactId>minafd</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>elitonlais.App</mainClass>
<launcher>launch.sh</launcher>
<compress>2</compress>
<jlinkZipName>MinAFD</jlinkZipName>
<jlinkImageName>MinAFD</jlinkImageName>
<includePathExceptionsInClasspath>true</includePathExceptionsInClasspath>
</configuration>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.Beta2</version>
<executions>
<execution>
<id>create-runtime-image</id>
<phase>package</phase>
<goals>
<goal>create-runtime-image</goal>
</goals>
<configuration>
<modulePath>
<path>${project.build.directory}/modules</path>
</modulePath>
<modules>
<module>module-info.java</module>
<!-- <module>javafx.controls</module>
<module>javafx.graphics</module> -->
</modules>
<launcher>
<name>test33</name>
<module>module-info.java/elitonlais.app</module>
</launcher>
<compression>2</compression>
<stripDebug>true</stripDebug>
<outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The entire project structure: https://github.com/EMachad0/MinAFD
Upvotes: 4
Views: 1776
Reputation: 9131
You should be able to add it following the documentation at the link Adding module descriptors to existing JAR files.
Adding the following to your existing pom.xml
as an additional <execution>
step for ModiTect should work:
<executions>
<execution>
<!-- your existing code here -->
</execution>
<execution>
<id>add-module-infos</id>
<phase>generate-resources</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<modules>
<module>
<artifact>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</artifact>
<!-- only use one of either moduleInfo or moduleInfoSource -->
<moduleInfo>
<name>guru.nidi.graphviz</name>
<exports>
*;
</exports>
<!-- possibly other fine-tuning -->
</moduleInfo>
<!-- only use one of either moduleInfo or moduleInfoSource -->
<moduleInfoSource>
module guru.nidi.graphviz {
requires ...;
exports ...;
provides ...
with ...;
}
</moduleInfoSource>
<!-- or use moduleInfoFile instead of the above -->
</module>
<module>
...
</module>
</modules>
</configuration>
</execution>
</executions>
Note also that the project has specified an automatic module name of guru.nidi.graphviz
so you'll need to change your own module-info
to require that, rather than the auto-derived graphviz.java
.
Upvotes: 1