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

我是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();
}

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

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

构建文件:C:\ test \ project \ workspace \ javafx-helloworld \ build \ build.xml

设置阶段区域:
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ externalLibs
[复制]将1个文件复制到C:\ test \ project \ workspace \ javafx-helloworld \ build \ externalLibs
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ project
[复制]将1个文件复制到C:\ test \ project \ workspace \ javafx-helloworld \ build \ project
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ projectRefs

做编译:
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ build \ src
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ build \ libs
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ build \ classes
[复制]将1个文件复制到C:\ test \ project \ workspace \ javafx-helloworld \ build \ build \ libs
[复制]将1个文件复制到C:\ test \ project \ workspace \ javafx-helloworld \ build \ build \ src
[javac]将1个源文件编译到C:\ test \ project \ workspace \ javafx-helloworld \ build \ build \ classes

init-fx-tasks:
[taskdef]无法从资源com / sun / javafx / tools / ant / antlib.xml加载定义。找不到。

做部署:
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ dist
[mkdir]创建的目录:C:\ test \ project \ workspace \ javafx-helloworld \ build \ dist \ libs
[复制]将1个文件复制到C:\ test \ project \ workspace \ javafx-helloworld \ build \ dist \ libs

**建立失败
C:\ test \ project \ workspace \ javafx-helloworld \ build \ build.xml:93:问题:创建任务失败或键入javafx:com.sun.javafx.tools.ant:resources
原因:名称未定义。
行动:检查拼写。
行动:检查是否已声明任何自定义任务/类型。
行动:检查是否已经/声明。
此命名空间中尚未定义任何类型或任务**

参考方案

现在有一个用于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中的<<或>>>是什么意思? - java

This question already has answers here: Closed 7 years ago. Possible Duplicate: What does >> and >>> mean in Java?我在一些Java代码中遇到了一些陌生的符号,尽管代码可以正确编译和运行,但对于括号在此代码中的作用却感…

菱形运算符<>是否等于<?> - java

我在util.TreeSet类中发现,其中一个构造函数正在使用具有空泛型类型的新TreeMap调用另一个构造函数。 public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<>(comparator)); } new TreeMap<>是什么意思…

休眠映射<键,设置<值>> - java

我有以下表格:@Entity @Table(name = "events") Event --id --name @Entity @Table(name = "state") State --id --name @Entity @Table(name = "action") Action --id …

无法从ArrayList <String>转换为List <Comparable> - java

当我写下面的代码时,编译器说 无法从ArrayList<String>转换为List<Comparable>private List<Comparable> get(){ return new ArrayList<String>(); } 但是当我用通配符编写返回类型时,代码会编译。private List&l…

合并List <T>和List <Optional <T >> - java

鉴于: List<Integer> integers = new ArrayList<>(Arrays.asList( 10, 12 )); List<Optional<Integer>> optionalIntegers = Arrays.asList( Optional.of(5), Optional.em…