简体   繁体   English

使用JavaFx插件制作可执行jar用于gradle

[英]Make executable jar with JavaFx plugin for gradle

I'm trying to make an executable jar. 我正在尝试制作一个可执行的jar。 My IDE is Netbeans 7.3.1, using Gradle plugin for Netabeans, using JavaFX plugin for Gradle. 我的IDE是Netbeans 7.3.1,使用Gradle插件为Netabeans,使用Gradle的JavaFX插件

Simple JavaFX application: 简单的JavaFX应用程序:

i.lunin.autoposting.Main: i.lunin.autoposting.Main:

package i.lunin.autoposting;

import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World! Man!");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
                System.out.println("Hello World!");
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}

Gradle file: Gradle文件:

build.gradle: 的build.gradle:

apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/0.3.0/javafx.plugin"
apply plugin: 'java'

sourceCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
    mavenCentral()
}

dependencies {
}

group = 'i.lunin.autoposting'
version = '0.0.0'

javafx {
    mainClass = 'i.lunin.autoposting.Main'
}

When I use gradle run , it runs perfectly inside my IDE; 当我使用gradle run ,它在我的IDE中完美运行; But I can't start it without IDE. 但是没有IDE我就无法启动它。

When I use gradle :jfxDeploy It says that the is finished. 当我使用gradle :jfxDeploygradle :jfxDeploy

After that, when I'm try to start the executable jar from: 之后,当我尝试从以下位置启动可执行jar时:

"... TestJava\\build\\distributions" “...... TestJava \\ build \\发行版”

It shows the following error: "Unable to find class: i.lunin.autoposting.Main" 它显示以下错误:“无法找到类:i.lunin.autoposting.Main”

Please help me make an executable jar under netbeans, gradle. 请帮我在netbeans,gradle下制作一个可执行jar。

I recently had the same issue. 我最近遇到了同样的问题。 For me it turned out to be the build system. 对我来说,它原来是构建系统。
If I build my app via gradle and javafx on a 32bit jvm, it resulted in the same error you had. 如果我通过gradle和javafx在32位jvm上构建我的应用程序,则会导致同样的错误。
If I built it on a 64bit system everything went fine. 如果我在64位系统上构建它,一切都很顺利。 So I guess it's still a problem to deploy self contained 32bit java apps. 所以我认为部署自包含的32位java应用程序仍然存在问题。 I tested it with Java 7. 我用Java 7测试过它。

There seems to exist a newer plugin which looks very promissing: 似乎存在一个看起来非常有用的新插件:

From the repository README: 从存储库README:

Using javafx-gradle-plugin enhances your build-script with javapackager-power. 使用javafx-gradle-plugin可以使用javapackager-power增强您的构建脚本。 No more using Apache Ant-calls, because this gradle-plugin wraps all calls and introduces workarounds and fixes for not-yet-fixed JDK-bugs. 不再使用Apache Ant调用,因为这个gradle-plugin包装了所有调用,并为尚未修复的JDK-bug引入了变通方法和修复程序。 This gradle-plugin is a convenient-wrapper for the javapackger, so you have to visit the official documentation to know about the requirements on each operating-system. 这个gradle-plugin是javapackger的便捷包装器,因此您必须访问官方文档才能了解每个操作系统的要求。

Why does this gradle-plugin exist? 为什么这个gradle-plugin存在?

In the need of some equivalent of the javafx-maven-plugin just for gradle, this project was born. 由于需要一些等效的javafx-maven-plugin只是为了gradle,这个项目诞生了。 A lot of you might have used the javafx-gradle-plugin from Danno Ferrin, but he decided to not continue that project. 很多人可能使用过Danno Ferrin的javafx-gradle-plugin,但他决定不继续该项目。

Check it out at https://github.com/FibreFoX/javafx-gradle-plugin 请访问https://github.com/FibreFoX/javafx-gradle-plugin查看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM