原文(原码)参考地址:
https://github.com/roskenet/springboot-javafx-support
https://github.com/spartajet/javafx-boot-demo
https://blog.spartajet.com/javafx-springboot-maven-kai-fa-da-bao-jiao-cheng/
自从用了springboot后就再也不想去写什么spring配置了,一看到以前的技术分分钟想死。
目录结构:
pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.spartajet</groupId> <artifactId>javafx-boot-demo</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.locales>zh_CN</project.build.locales> <java.version>1.8</java.version> <project.build.jdk>${java.version}</project.build.jdk> <spring.boot.version>1.5.1.RELEASE</spring.boot.version> <springboot-javafx-support.version>1.3.15</springboot-javafx-support.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>${spring.boot.version}</version> <exclusions> <!-- 剔除logging --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>${spring.boot.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>de.roskenet</groupId> <artifactId>springboot-javafx-support</artifactId> <version>${springboot-javafx-support.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.zenjava</groupId> <artifactId>javafx-maven-plugin</artifactId> <configuration> <mainClass>example.Main</mainClass> <vendor>Spartajet</vendor> </configuration> </plugin> </plugins> </build> </project>
Main.java:
package example; import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport; import javafx.stage.Stage; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Main extends AbstractJavaFxApplicationSupport { public static void main(String[] args){ //launch(Main.class,HelloworldView.class,args); launchApp(Main.class,HelloworldView.class,args); } @Override public void start(Stage stage) throws Exception { super.start(stage); } }
HelloworldView.java:
package example; import de.felixroske.jfxsupport.AbstractFxmlView; import de.felixroske.jfxsupport.FXMLView; @FXMLView(value = "/example/Helloworld.fxml") public class HelloworldView extends AbstractFxmlView { }
Helloworld.fxml:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.131" xmlns:fx="http://javafx.com/fxml/1"> <children> <Label layoutX="244.0" layoutY="121.0" prefHeight="157.0" prefWidth="211.0" text="HELLO WORLD!" /> </children> </Pane>