【问题标题】:Bundle java app for mac distribution捆绑用于 mac 分发的 java 应用程序
【发布时间】:2015-05-18 08:46:44
【问题描述】:

我一直在尝试使用 Oracle 的 appbundler 创建一个适用于 Mac 的 .app。我创建了一个示例 javaFX 代码,场景中只显示了一个按钮。以下是我的主课。

Main.java

package app;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;


public class Main extends Application {

    private void init(Stage primaryStage) throws Exception {
        Button root = new Button("Hello world!");
        Scene scene = new Scene(root,150,50);
        primaryStage.setScene(scene);
    }

    @Override
    public void start(Stage primaryStage) {
        try {
            init(primaryStage);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

当我从 Eclipse 运行它时,它可以工作。所以我创建了一个 ant 脚本来捆绑应用程序:

构建.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="builder" default="build-app" basedir=".">

    <property name="src" value="src" />
    <property name="build" value="build" />
    <property name="lib" value="lib" />

    <!-- Target init -->
    <target name="init" description="generate build folder">
        <delete dir="${build}" />
        <mkdir dir="${build}" />
    </target>


    <!-- Build app -->
    <target name="build-app" depends="init">
        <echo>Building files</echo>
        <javac destdir="${build}" includeantruntime="true">
            <src path="${src}/app" />
        </javac>
    </target>

    <!-- Build app -->
    <target name="gen-jar" depends="build-app">
        <jar destfile="${lib}/app.jar" basedir="${build}/app"/>
    </target>


    <!-- BUNDLE APP -->
    <target name="bundle-sample" depends="gen-jar">
        <taskdef name="bundleapp"
            classname="com.oracle.appbundler.AppBundlerTask"   
            classpath="lib/appbundler-1.0.jar" />

        <bundleapp outputdirectory="."
            name="sample"
            displayname="sample"
            identifier="sample"
            mainclassname="app.Main">

            <!-- jdk directory -->
            <runtime dir="/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home"/>

            <classpath file="lib/app.jar" />
        </bundleapp>
    </target>

</project>

我现在可以通过运行成功构建 ant 脚本:

ant bundle-sample

虽然当我运行应用程序时出现以下错误

open sample.app
LSOpenURLsWithRole() failed with error -10810 for the file sample.app

有人知道 build.xml 有什么问题吗?

【问题讨论】:

    标签: java eclipse macos oracle ant


    【解决方案1】:

    当您使用 Eclipse 时,我建议您使用 e(fx)clipse 插件,然后按照本教程进行操作。它对我有用。

    http://code.makery.ch/library/javafx-8-tutorial/part7/

    祝你好运 迈克尔

    【讨论】:

      猜你喜欢
      • 2012-05-29
      • 2015-03-28
      • 2014-10-08
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多