The jlink
要求所有依赖项都是模块化的。生成后,它会生成一个包含所需模块的自定义 JRE 映像。这ini4j
似乎是非模块化的。
对于非模块化依赖项,您可以在获取未使用非模块化依赖项生成的自定义 JRE 后使用旧的类路径方法。
简而言之,运行 jlink 排除非模块,然后将非模块的 jar 文件添加到生成的 JRE 映像中。模块方法和类路径方法可以通过这种方式组合。
稍微摆弄 Maven 插件应该会自动完成此操作。
示例ini4j
pom.xml
<properties>
<jlink-image-name>JUSBPlotter</jlink-image-name>
<ini4j-jar-name>ini4j.jar</ini4j-jar-name>
</properties>
- Disable
ini4j
from module-info.java
(应该在开发时启用,只有在要打包项目时才这样做)
module org.openjfx.JUSBPlotter {
requires javafx.controls;
requires javafx.fxml;
requires com.fazecast.jSerialComm;
//requires ini4j;
requires org.apache.commons.io;
opens org.openjfx.JUSBPlotter to javafx.fxml;
exports org.openjfx.JUSBPlotter;
}
- 配置
maven-dependency-plugin
复制 jar 文件ini4j
进入lib/
jlink 图像中的文件夹。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<!-- Copy ini4j jar into the jlink image -->
<artifactItem>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
<type>jar</type>
<destFileName>${ini4j-jar-name}</destFileName>
</artifactItem>
</artifactItems>
<!-- Set output directory to lib folder in jlink image -->
<outputDirectory>${project.build.directory}/${jlink-image-name}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
- 配置
jlink
中的启动器选项javafx-maven-plugin
为了添加非模块化的jar文件ini4j
到类路径。
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<stripDebug>true</stripDebug>
<compress>2</compress>
<noHeaderFiles>true</noHeaderFiles>
<noManPages>true</noManPages>
<launcher>JUSBPlotter</launcher>
<jlinkImageName>JUSBPlotter</jlinkImageName>
<mainClass>org.openjfx.JUSBPlotter.Main</mainClass>
<!-- ini4j jar file will be copied to the {image-folder}/lib/ folder. The launcher script should have this option to add it to the classpath -->
<options>-cp ../lib/${init4j-jar-name}</options>
</configuration>
</plugin>
Run:
mvn clean javafx:jlink
mvn package
cd target/JUSBPlotter/bin
./JUSBPlotter
maven-dependeny-plugin
运行时会复制 jar 文件mvn package
。但 jlink 镜像必须已经生成。所以运行mvn javafx:jlink
第一的。然后运行mvn package
.
Refer here看看我是如何申请的sqlite-jdbc
在我的项目中。