Eclipse 配置或搭建 非模块化 JavaFX 开发环境

JavaFX 非模块化开发环境搭建

创建maven项目  File -New-Maven Project

添加依赖项绕过模块化的重点是直接通过classifier选择当前运行的平台win 如果是linux或mac 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.vk</groupId>
  <artifactId>vkfx</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <javafx.version>21.0.8-ea+1</javafx.version>
  </properties>
  <dependencies>
	<dependency>
	    <groupId>org.openjfx</groupId>
	    <artifactId>javafx-base</artifactId>
	    <version>${javafx.version}</version>
	    <classifier>win</classifier>
	</dependency>
	<dependency>
	    <groupId>org.openjfx</groupId>
	    <artifactId>javafx-controls</artifactId>
	    <version>${javafx.version}</version>
	    <classifier>win</classifier>
	</dependency>
	<dependency>
	    <groupId>org.openjfx</groupId>
	    <artifactId>javafx-graphics</artifactId>
	    <version>${javafx.version}</version>
	    <classifier>win</classifier>
	</dependency>
	<dependency>
	    <groupId>org.openjfx</groupId>
	    <artifactId>javafx-fxml</artifactId>
	    <version>${javafx.version}</version>
	    <classifier>win</classifier>
	</dependency>
	<dependency>
	    <groupId>org.openjfx</groupId>
	    <artifactId>javafx-media</artifactId>
	    <version>${javafx.version}</version>
	    <classifier>win</classifier>
	</dependency>
	<dependency>
	    <groupId>org.openjfx</groupId>
	    <artifactId>javafx-swing</artifactId>
	    <version>${javafx.version}</version>
	    <classifier>win</classifier>
	</dependency>
  </dependencies>
</project>

示例代码 注意main函数不能写在Application子类中当前即是(VKFxApplication),否则会出现错误

错误: 缺少 JavaFX 运行时组件, 需要使用该组件来运行此应用程序

package com.vk;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class VKFxApplication extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		BorderPane pane = new BorderPane();
		Label b1 =new Label("Victorkevin");
		pane.setCenter(b1);
		Scene scene = new Scene(pane, 400, 400);
		stage.setScene(scene);
		stage.setTitle("Vk demo");
		stage.show();
	}
}

运行启动方式代码,注意的是通过LauncherImpl释放应用程序 效果如下图

package com.vk;

import com.sun.javafx.application.LauncherImpl;
public class VKMain {
	public static void main(String[] args) {
		System.out.println("start it");
		LauncherImpl.launchApplication(VKFxApplication.class, args);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

victorkevin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值