【发布时间】:2021-10-09 22:30:38
【问题描述】:
使用 jpackage 我无法让 pkg 在 macOS 上运行。安装按预期进行,但是当我启动已安装的应用程序时,它会立即停止。
尝试通过 CLI 启动它并抛出
Error: Could not find or load main class com.example.Application
Caused by: java.lang.ClassNotFoundException: com.example.Application
我已将MainClass 参数作为com.example.Application 传递,我可以在Contents/app/example.jar 下的已安装包中看到它。
使用 Gradle 插件 id "org.panteleyev.jpackageplugin" version "1.3.1" 构建原生安装程序:
def os = org.gradle.internal.os.OperatingSystem.current()
def pkgType = os.windows ? 'msi' : os.linux ? 'deb' : 'pkg'
def inputDir = "$buildDir/input"
task copyDependencies (type: Copy) {
from configurations.runtimeClasspath
into inputDir
}
task copyJar (type: Copy) {
from tasks.jar
into inputDir
}
jpackage {
dependsOn clean
dependsOn bootJar
dependsOn copyDependencies
dependsOn copyJar
type = pkgType
input = inputDir
destination = "$buildDir/dist"
appName = 'Example'
vendor = 'com.example'
mainJar = tasks.jar.getArchiveFileName().get()
mainClass = 'com.example.Application'
javaOptions = ['-Dfile.encoding=UTF-8']
}
当通过 IntelliJ/通过 CLI 启动时,jar 运行良好。
我还需要在这里做什么?
【问题讨论】: