我正在使用带有 Gradle 的 Jlink 和 Jpackage 来生成适用于 Windows 10 的安装程序。构建成功,但生成的 exe 是一个空文件。生成的文件只是一个没有扩展名的 0kb 文件,空文件的名称是应用程序的名称。不知道我的步骤出了什么问题。我正在使用 JDK 14 并安装了 Wix 安装程序,但我认为它没有做任何事情。
我的build.gradle文件
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
id 'org.beryx.jlink' version '2.24.0'
}
group 'com.calendar'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
javafx {
version = "16"
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.web' ]
}
dependencies {
implementation group: 'org.apache.commons', name:'commons-lang3', version: '3.10'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.13.1'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
implementation group: 'com.opencsv', name: 'opencsv', version: '5.4'
implementation group: 'com.google.inject', name: 'guice', version: '5.0.1'
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
implementation group: 'org.xerial', name:'sqlite-jdbc', version:'3.34.0'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.4.31.Final'
implementation group: 'com.github.gwenn', name: 'sqlite-dialect', version: '0.1.2'
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.4.3'
implementation group: 'org.ini4j', name: 'ini4j', version: '0.5.4'
implementation group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.3.3'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
ext {
moduleName = 'Calendar'
moduleLaunchPoint = 'com.calendar.Calendar'
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'CalendarApp'
jvmArgs = [
"--add-opens", "--add-opens java.base/java.lang=ALL-UNNAMED --module-path \"C:\\Program Files\\JavaFX-SDK-16.0.1\\lib\" --add-modules javafx.controls,javafx.fxml,javafx.web"
]
}
mergedModule {
requires 'java.logging';
requires 'java.sql';
requires 'jdk.jdi';
requires 'java.rmi';
requires 'java.xml';
requires 'com.sun.xml.txw2';
requires 'java.desktop';
requires 'java.management';
requires 'java.naming';
requires 'jdk.attach';
requires 'java.scripting';
requires 'java.datatransfer';
requires 'java.compiler';
requires 'java.transaction.xa';
requires 'com.sun.xml.fastinfoset';
requires 'java.instrument';
uses 'javax.persistence.spi.PersistenceProvider';
provides 'javax.persistence.spi.PersistenceProvider' with 'org.hibernate.jpa.HibernatePersistenceProvider';
}
jpackage {
// if(org.gradle.internal.os.OperatingSystem.current().linux){
// installerType = "deb"
// jpackageHome = "/usr/lib/jvm/jdk-14.0.2"
// }else if(javafx.getPlatform().name()=="WINDOWS") {
installerType = "exe"
jpackageHome = "C:\\Users\\janetwu\\Documents\\jdk-14.0.2"
installerOptions += ['--win-per-user-install', '--win-dir-chooser', '--win-menu', '--win-shortcut']
// }
// else if(javafx.getPlatform().name()=="OSX"){
// installerType = "dmg"
// jpackageHome = "/usr/lib/jvm/jdk-14.0.2"
// }
}
}
tasks.jlink.doLast {
copy {
from("ar-sy.lang")
into("$buildDir/image/bin")
}
copy {
from("ext-resources")
into("$buildDir/image/bin/ext-resources")
}
}
application {
mainModule = "com.calendar"
mainClass = "com.calendar.Calendar"
}
mainClassName = "${moduleName}/${moduleLaunchPoint}"
模块信息.java
module com.calendar{
requires javafx.fxml;
requires javafx.controls;
requires javafx.web;
requires com.google.guice;
requires org.slf4j;
requires static lombok;
requires freemarker;
requires com.google.gson;
requires org.hibernate.orm.core;
requires modelmapper;
requires java.naming;
requires java.persistence;
requires java.xml.bind;
opens com.calendar to javafx.fxml;
opens com.calendar.controllers to javafx.fxml;
opens com.calendar.storage to org.hibernate.orm.core,javafx.base;
exports com.calendar;
}