简体   繁体   English

如何使用maven构建可运行的JavaFX应用程序?

[英]How to build a runnable JavaFX application using maven?

I am new to JavaFX. 我是JavaFX的新手。 I have created a Hello World project using maven. 我使用maven创建了一个Hello World项目。 It works fine when I run it in Eclipse. 当我在Eclipse中运行它时,它工作正常。

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

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("Hello World!");
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    btn.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Hello World!");
        }
    });
    StackPane root = new StackPane();
    root.getChildren().add(btn);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}

你好,世界

I found the deployment tutorial , but when my program comes with maven, I have no idea how to build it. 我找到了部署教程 ,但是当我的程序带有maven时,我不知道如何构建它。

When I try to build the application using build.fxbuild, I got this error. 当我尝试使用build.fxbuild构建应用程序时,我收到此错误。

Buildfile: C:\test\project\workspace\javafx-helloworld\build\build.xml

setup-staging-area:
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\externalLibs
        [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\externalLibs
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\project
        [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\project
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\projectRefs

do-compile:
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\build\src
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\build\libs
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\build\classes
        [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\build\libs
        [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\build\src
       [javac] Compiling 1 source file to C:\test\project\workspace\javafx-helloworld\build\build\classes

init-fx-tasks:
     [taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.

do-deploy:
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\dist
       [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\dist\libs
        [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\dist\libs

**BUILD FAILED
C:\test\project\workspace\javafx-helloworld\build\build.xml:93: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
No types or tasks have been defined in this namespace yet**

There is now a maven plugin for JavaFX: 现在有一个JavaFX的maven插件:

https://github.com/zonski/javafx-maven-plugin https://github.com/zonski/javafx-maven-plugin

<plugin>
    <groupId>com.zenjava</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>package</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>[put your application main class here]</mainClass>
        <bundleType>ALL</bundleType>
    </configuration>
</plugin>

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

相关问题 如何使用 maven 为生产构建 Javafx + Spring - How to build Javafx + Spring for production using maven 可运行的Javafx应用程序中的Unirest - Unirest in a runnable javafx application 如何使用Maven + JavaFX创建可运行的JAR文件 - How can I create a runnable JAR file with Maven + JavaFX 如何为没有本机安装程序的使用 JavaFX 的应用程序制作可运行的 jar - How to make a runnable jar for an application that uses JavaFX without native installers 使用 Maven 构建的 Java 应用程序 - Java application using Maven Build 使用 Java Swing 和集成的 JavaFX 通过 Maven 创建可运行的 .jar - 实例化 JFXPanel 时应用程序崩溃 - Creating a runnable .jar with Maven using Java Swing and integrated JavaFX - App crashes when JFXPanel is being instantiated Runnable Jar(JavaFx)使用spring boot maven插件作为构建器找不到log4j2.xml - Runnable Jar (JavaFx) cannot find log4j2.xml using spring boot maven plugin as builder "在使用 Maven 构建的 Swing 应用程序中运行 JavaFx 时缺少 SwingInterOpUtils" - Missing SwingInterOpUtils when running JavaFx in an Swing application build with Maven Maven:使用 Inno Setup 脚本构建 javaFX 应用程序的本机安装程序 - Maven : Build native installer of javaFX application with Inno Setup script 如何正确地将JavaFX 8应用程序迁移到Maven? - How to correctly migrate a JavaFX 8 application to Maven?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM