对于使用 jpackage

问题描述

不久前我用 jpackage 构建了我的应用程序安装程序。

我在我的开发机器(macos 版本 10.15.2)和另一台稍旧的机器(macos 版本 10.12.6)上测试了它。程序在两台机器上都运行得很完美。

自从上次测试以来,我的程序不断发展,我想重复这个部署测试。在我的开发机器上,一切都按预期进行,而在另一台机器上,我现在收到此消息:

“LSOpenURLsWithRole() 失败,文件 /Applications/myApplication.app 出现错误 -10810。”

我能找到的唯一痕迹(在 /var/log/system.log 中)是这样的: “7 月 23 日 12:03:29 iMac com.apple.xpc.launchd 1 (com.myAppPackage.main.24860 [4219]):服务退出,异常代码:1”

这对我来说意义不大。

正如我一开始假设问题的原因出在新代码上的那样,我尝试通过简化越来越多的代码来进行跟踪测试,直到最终得到一个比原来更简单的版本(非常简单)第一次表现正确。但仍然是相同的情况,在我的机器上,应用程序启动没有问题,而在另一台机器上出现此错误 -10810。

另一方面,如果我在第二台机器上运行 jar 文件,一切正常。

我不知道第二台机器上是否有任何变化,但现在我觉得我用 jpackage 构建的所有东西都拒绝在这台机器上运行。我也有一种感觉,Java 代码甚至没有运行或没有引起问题。

暂时没有阻塞,但如果没有解决方案,它会有点令人担忧。

如果有人有关于如何调查的想法甚至信息,我欢迎他们。

这是一个重现的例子:

主类和JavaFx窗口(无包)

public class MainApp {
    
    private static MainApp singleton;
    
    public static void main(String[] args) {
        singleton = new MainApp();
        BootLogs.inition(args,singleton);
    }

    public void bootInit() {
        BootLogs.addText("Enter main().");
    }
}
import java.io.PrintWriter;
import java.io.StringWriter;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class BootLogs extends Application {

    private static MainApp mainApp;
    
    private static BootLogs singleton;
    
    private VBox messageVbox = new VBox();
    private TextArea txtArea = new TextArea();
    
    public static void inition(final String[] args,final MainApp mainApp) {
        BootLogs.mainApp = mainApp;
        launch(args);
    }
    
    @Override
    public void start(Stage stage) throws Exception {
        singleton = this;
        
        stage.setTitle("Boot logs");
        
        StackPane root = new StackPane();
        root.setStyle("-fx-border-width: 30;-fx-border-color: gray;");
        root.getChildren().add(messageVbox);
        
        messageVbox.getChildren().add(txtArea);
        
        VBox.setVgrow(txtArea,Priority.ALWAYS);
        txtArea.setEditable(false);
        
          
        stage.setScene(new Scene(root,450,450));
        stage.centerOnScreen();
        messageVbox.setVisible(true);
        
        Platform.setImplicitExit(true);
        Platform.runLater(() -> mainApp.bootInit());
        
        stage.show();
    }

    public static void addText(String txt) {
        singleton.txtArea.setText(singleton.txtArea.getText() + "\n" + txt);
    }
    
    public static void addText(String txt,Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        singleton.txtArea.setText(singleton.txtArea.getText() + "\n" + txt + pw.toString() + "\n");
    }
}

build.gradle 文件:

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'
    id 'eclipse'
    
    //Plugin javafx.
    id 'org.openjfx.javafxplugin' version '0.0.10'
}

repositories {
    // Use JCenter for resolving dependencies.
    jcenter()
}

dependencies {
    
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
    
}

javafx {
    version = "11"
    modules = [ 'javafx.controls','javafx.fxml','javafx.swing' ]
}

tasks.named('jar') {
    
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    
    inputs.files( configurations.runtimeClasspath )

    manifest {
        attributes('Implementation-Title': project.name,'Implementation-Version': '1.0','Main-Class': 'MainApp')
    }
        
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

jpackage选项(eclipse项目名称为ZD):

/Library/Java/JavaVirtualMachines/zulu15.32.15-ca-jdk15.0.3-macosx_x64/zulu-15.jdk/Contents/Home/bin/jpackage \
-i /Users/ ... /ZD/external_resources \
-n AppTest \
--main-class MainApp \
--main-jar /Users/ ... /ZD/app/build/libs/app.jar \
--icon /Users/ ... /ZDInstaller/AnyConv.com__graou_logo_77_66_0.icns

在两台机器上安装MainApp没有问题。

这是在我的机器上启动的应用程序:

enter image description here

但在另一台机器上(我也测试了此处显示的示例)仍然存在错误 -10810。我提醒您,在 3 到 4 周前,更简单的代码已经起作用了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)