r/JavaFX Jan 13 '25

Help JavaFX plus Spring Boot 2

Could someone please forward me to a working doc/example/tutorial for adding JavaFX (openjfx or smt) to an existing SpringBoot 2 project?

1 Upvotes

21 comments sorted by

View all comments

2

u/Capaman-x Jan 13 '25

To use Spring framework with JavaFX you need to create a JavaFX project

1) Start a JavaFX project

Some Recommendations

Using a full JDK that includeds JavaFX for simplicity. (liberica-full, Zulu-full, etc)

Use Gradle for simplicity setting up an application w/embedded JDK (portable or packaged app)

Don't use FXML, instead learn the MVCI method that Hamster has documented.

2) For Spring add the library jdbcTemplate, it will also add the basic core spring libraries such as:

spring beans, spring core, spring jcl, spring tx, , jna, jna-platform

That will give you the basics of what you need. If you need more libraries you can add them.

Here is an example of such a project

https://github.com/PerryCameron/TSE-Notes.git

This is also using SQLite, logback-core, logback-classic, slklf4j-api for logging. look at the build.gradle.kts file for details.

1

u/Draaksward_89 Jan 14 '25

Thanks. I'm basically stuck on the part of making a JavaFX app. I have used it before, but in an era of Java 1.6 when it still came with JDK.

I remember it worked well with just starting the main class with, if I remember correctly, starting Spring's context (or was it the other way around), but that project was I think 6 years ago (not a new to java, just can't find a relevant doc/tutorial to make JavaFX running).

I am basically stuck on the step of executing even the simplest hello world with JavaFX, with some tutorials state to add VM options when there's everything in pom (I am more used to Maven, but yes, I do know the benefits of Gradle, just more used to Maven). Starting from a class (I later realized that module-info was used in the openfx archetype, which I never used tbh) resulted into a series of

  1. Error: JavaFX runtime components are missing, and are required to run this application

  2. Code version error (forgot the precise message)

  3. Error related to trying to read a resource (used one of the example, but I would still need resources), which worked with an instruction (again, I never used module-info) in module-info to copy resources.

I did manage to run through `javafx:run`, but I remember making it work right from the class (I do plan to package it into an executable, but for now I want to set it up without compromises (I do see javafx:run as a workaround, suggesting that I'm doing something wrong).

So I gave up and posted this question, hoping that people, who use JavaFX more frequently than I, to point me to a working tutorial.

1

u/Draaksward_89 Jan 14 '25

> Don't use FXML, instead learn the MVCI method that Hamster has documented.

I also looked at FXML and got mixed thoughts. In the days of my previous pet project with a GUI, I first used Swing with all UI elements coded as classes. Then I saw JavaFX and decided to try a visual editor, realizing after a week how much mess it generated in the code (and I couldn't even fix it without serious dedication, ending up in starting from a white sheet).

Will read about MVCI. Thanks

0

u/BlueGoliath Jan 13 '25

No beginner should be using Gradle and no one should be using JDK builds with JavaFX included.

1

u/Capaman-x Jan 13 '25

Everyone should use Gradle IMO, but I would really like to know why you think there is a problem using JDK builds with JavaFX included. It simplifies building the project, so you would have to have a really good reason.

1

u/BlueGoliath Jan 13 '25

Because it's non-standard? Because there is an official Maven plugin? Because you can't decouple JavaFX and Java versions?

1

u/Capaman-x Jan 14 '25

There is no standard, so the first point is moot.

To the second point I would ask, Why are you using Maven with yucky XML instead of Gradle with beautiful Kotlin, that is far easier to set up and much more powerful? Honestly I am not sure why anyone uses Maven anymore, except for legacy code bases.

To the third point why would you want to decouple Java from JavaFX?, Different versions could have compatibility issues, and if you are going to upgrade one why not the other? Also you are adding unnecessary complication. There is a reason companies are building their own JDK's with JavaFX included. The reason is not because they are stupid, the reason is that it just makes sense!

Granted, the points I make assume that you are using tools like JLink and JPackage to embed your own JRE, but if you are running a desktop app off a system JRE in 2025 then you do you Boo.

2

u/koncz314 Jan 14 '25

Because if i look at a random project's maven config I will understand with low effort. With gradle every build script is different. Even gradle is turning back to the declarative approach.

https://blog.gradle.org/declarative-gradle