首页 > 解决方案 > 对于使用 jpackage 构建的应用程序,LSOpenURLsWithRole() 失败并出现错误 -10810

问题描述

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

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

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

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

我能找到的唯一痕迹(在 /var/log/system.log 中)是这样的:“Jul 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 没有问题。

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

在此处输入图像描述

但是在另一台机器上(我也测试了这里显示的示例)仍然存在错误-10810。我提醒你,在 3 到 4 周前,更简单的代码已经奏效了。

标签: javamacosjpackage

解决方案


我不知道这是否是最好的解决方案,但我想我已经找到了解决方案。

在 macos 版本 10.15 中,从使用 jpackage 创建的“.dmg”安装的可执行文件适用于此版本 10.15,但不适用于版本 10.12。事实证明,反之亦然:在 macos 10.12 版本中使用 jpackage 创建的“.dmg”安装的可执行文件适用于 10.12 版,但不适用于 10.15 版。

即使我没有检查其他版本,可执行文件也很有可能在 macos 版本中运行,您必须在同一 macos 版本中通过 jpackage 构建“.dmg”。


推荐阅读