gpt4 book ai didi

java - 如何使用 Maven 构建可运行的 JavaFX 应用程序?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:33 26 4
gpt4 key购买 nike

我是 JavaFX 的新手。我已经使用 maven 创建了一个 Hello World 项目。当我在 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();
}

hello_world

我找到了 deployment tutorial , 但是当我的程序带有 maven 时,我不知道如何构建它。

当我尝试使用 build.fxbuild 构建应用程序时,出现此错误。

Buildfile: C:\test\project\workspace\javafx-helloworld\build\build.xmlsetup-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\projectRefsdo-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\classesinit-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 FAILEDC:\test\project\workspace\javafx-helloworld\build\build.xml:93: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resourcesCause: 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**

最佳答案

现在有一个 JavaFX 的 maven 插件:

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>

关于java - 如何使用 Maven 构建可运行的 JavaFX 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13004958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com