B4J Question More recent JDK versions do not work with B4J

RacingDog

Active Member
Licensed User
I know nothing about Java as I have a list a mile long of languages I know and therefore I don't need any more on the list. I'm only interested in B4J because I am 77 (i.e. retired) and run out of things I want to do with Lazarus and I used to be a Basic4PPC user! So...

Once upon a time I used to use Version 8 of JDK but at some stage some app I was installing said it wanted JDK-24 so I dutifully started using that instead. Other apps that need Java didn't complain. So when I recently downloaded B4J I took the web site's advice that if I already had JDK I didn't need to reacquire and reinstall. Yesterday I finally got round to actually using B4J so followed the documentation and create MyFirstProgram. On trying to compile I got the following result...

****************************
B4J Version: 10.70
Parsing code. (0.02s)
Java Version: 8
Building folders structure. (0.01s)
Running custom action. (0.04s)
Compiling code. (0.06s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
src\B4J\MyFirstProgram\main.java:7: error: package javafx.application does not exist
public class main extends javafx.application.Application{
^
1 error
only showing the first 1 errors, of 7 total; use -Xmaxerrs if you would like to see more

javac 24.0.1


Tip: press Ctrl + R to export IDE state for AI assistants.
************************************************

After poking around on my system and not finding an answer I decided to follow the link from the B4X web site for downloading JDK. I found that that version 19 was being specified. So I downloaded that and lo, MyFirstProgram compiled and ran! But that means I need to be running two versions of JDK as the version 19 download is a "portable" version requiring no installation so other apps don't know it is there so I still need to have version 24 installed!

Yes I know version 24 is not the latest, but it works perfectly with everything else I've got. But further investigation of the Java website says that end users like me should still be using version 8! Really??? And why does that error message say Java Version 8 when it is version 19 that that download link specifies?

So why has the javafx.application.Application package disappeared from later versions of JDK? I suspect it may be because there is now a separate product OpenFX and they thought having an unrelated package with an fx suffix might be confusing. So maybe it is possible that that package is still in the JDK but using a different name? Perhaps a Java expert out there would know? If that is the case, sadly B4J should be given the extra ability to cope with both situations. Otherwise it needs to be made clear that versions of JDK after whatever number was the first to drop javafx are not suitable.
 

aeric

Expert
Licensed User
Longtime User
Not very clear what you mean.
If you want to use JDK+JavaFX other from the version 19, you can check this post.
 
Upvote 0

RacingDog

Active Member
Licensed User
Sigh! I already said I eventually used that link. But I was initially working from an inaccurate statement in the help documentation

The statement in question is in the Getting Started document section 2.3 which says "If you have already installed Java no need to re-install it". That is not accurate as, using the rules of normal English, that means any version or configuration of Java, and that is not what you meant. But I took it literally, I had already installed just JDK-24 ages ago, which is "having Java installed", hence everything that followed. Everything that followed included confusion from not knowing what comes from what source. As I said initially, Java is not something I know about, or want to know about, otherwise I would now be experimenting with Java not B4J.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
There are 2 types of Java.

1st is JDK, where we unzip the zip file and use the jars or tools from the /bin for development of apps.

2nd is JRE, where you can install from installer which is use for end users to run apps already build by Java.

Java 8 (1.8) usually pre-installed in Windows also has JavaFX.
It could be after Java is acquired by Oracle, the company decided to separate the JavaFX from Java core libraries for JDK11 and beyond.
Therefore the official JDK website doesn't provide JavaFX on their website.
You can find other unofficial websites like BellLabs or Microsoft which host Java JDK with JavaFX.
Some server or console (non-UI) apps don't need the UI libraries.
(B4A also don't need JavaFX, but it can use the same JDK+JavaFX path)

If you just download JDK24 from official website, probably it doesn't contain JavaFX for building UI apps. You also need to download and unzip JavaFX following the correct structure required by B4J.
This is a bit confusing and advanced for new developers but it is what Java team provided, not by B4X.

tldr;
If you want something "just works" for B4J out of the box, just use the JDK19 as recommended in B4J install page.

You probably don't need other versions and newer versions don't mean better.
 
Last edited:
Upvote 0
Top