When I was looking for information about when to create a Maven + Spring + JavaFX project, I constantly encountered the following problems:

  1. Constantly getting into the search results are some libraries that offer their own architecture and configuration of a project like Spring Boot. I’m also interested in JavaFX and Spring as separate libraries that do not involve large-scale changes in the configuration and structure of an existing project.
  2. I did not find a single example with a single way to determine maven dependencies. Here for example an article on Habré about the integration of Maven, Spring, JavaFX. Fine. Only where in pom.xml is JavaFX listed among dependencies? In this example, we add JavaFX to the plugins field. This is also a failure: somehow annoying when spring is in dependencies, and javafx is in plugins.
  3. There are plenty of JavaFX libraries in Maven repositories , and which one to use is not clear. Naturally, we are primarily interested in maven-dependence on the official developer, that is, Oracle, and libraries from third parties are undesirable.

Generally speaking, to answer this question, it is enough to add the dependency dependencies to the official developer of this technology in the POM.xml below, which defines the basic JavaFX functionality.

<?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.example</groupId> <artifactId>JavaFX_Spring_Maven</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.0.8.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>5.0.8.RELEASE</version> </dependency> </dependencies> </project> 
  • one
    JavaFX is a ready-made solution from Java developers and is in the JDK. Connect the JDK and use. The concept "Java JX Application" implies that a special structure will be used: Main.java , main.fxml and MainController.java and of course the code. Libraries extend core JavaFX functionality - Tsyklop

1 answer 1

Before JRE 9, JavaFX was in jfxrt.jar, which was part of the JRE. In JRE 7, this jar needed to be added to the classpath. In JRE 8, this was no longer necessary, since there jfxrt.jar was placed in the lib / ext directory in the JRE. In JRE 9, JavaFX has become a module that comes with the JRE and also does not require any gestures for its accessibility. At the end of this month’s Java 11 release, this module will no longer be part of the JRE and will have to be installed separately. Obviously, you are using Java 8 or Java 10 and JavaFX is available to you automatically.

PS I would add the compilation parameters to your pom.xml according to the JDK you are using:

 <properties> <maven.compiler.source>10</maven.compiler.source> <maven.compiler.target>10</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> 

or

 <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> 

I would also register a newer Spring 5.0.9 in dependencies

  • Thank you for your reply! Since I use the newest technologies, I will be guided by Java 11. What do you mean by "separate installation"? Will there be a new Maven repository with JavaFX for Java11? - Lateral Gleb
  • one
    Then you better wait until Java 11 and Spring 5.1 are released at the end of September. JavaFX, broken into several modules, will be available from the central Maven repository at mvnrepository.com/artifact/org.openjfx Pre -release EA versions are now available there. With Java 10, they are unlikely to work correctly. Wait, quite a bit of java-countdown.xyz is left - Rostislav Krasny
  • Well, perhaps I will do as you said. Thank you for the answer! - Bokov Gleb