如何使用Maven构建可运行的JavaFX应用程序?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何使用Maven构建可运行的JavaFX应用程序?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2915字,纯文字阅读大概需要5分钟。
内容图文
![如何使用Maven构建可运行的JavaFX应用程序?](/upload/InfoBanner/zyjiaocheng/676/3e140e56ed2441cf892c5f7f06d91d4d.jpg)
我是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构建应用程序时,出现此错误.
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**
解决方法:
现在有一个用于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>
内容总结
以上是互联网集市为您收集整理的如何使用Maven构建可运行的JavaFX应用程序?全部内容,希望文章能够帮你解决如何使用Maven构建可运行的JavaFX应用程序?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。