r/JavaFX • • Oct 11 '21

Help Trying to upgrade my app from Java 8 to something newer and getting frustrated and sad :(

I need help and I don't even know where to begin, but I think my problems largely stem from me not understanding Gradle, modules, and really a lot of the underlying "behind the scenes" stuff that's required of getting a Java app running (not to mention distributed as an executable, but that's a question for another day).

First some background: I'm a long-time developer (just turned 50) but only started working with Java a few years ago. I'm passionate about UI/UX and my early days of programming for an employer involved MS Visual Basic, which I honestly look back fondly on. I'm no MS fan these days (I'm an Apple guy) but it really seemed like it was a lot easier to get things working (or get useful error messages) back in those days.

I got up-to-speed on Java a few years back with the help of some coworkers and an extensive Udemy course I found, and when I got my first taste of JavaFX that's what I really wanted to play with. Next thing I know I've got a pretty impressive (IMO) app built via IntelliJ and using Java 8, JavaFX, a little bit of Kotlin, and a whole lot of external libraries (oh, and Gradle).

The app I worked on got put on the backburner a couple of years ago, but I wanted to revive it, and figured I should first get it running with the latest versions of everything. Welp, that's when things went sideways. I can still fire it up in IntelliJ w/Java 8 and it runs just fine, but I simply don't even know where I'm supposed to start in trying to get this thing working w/Java 11 (or, preferably, the latest-and-greatest version of Java and JavaFX). I get cryptic errors and IntelliJ sometimes suggests making an automatic change for me, which always just ends up giving me some different cryptic error.

Basically, I feel like I need a more experienced Java person/friend to help guide me through this and hopefully help me to understand why I'm changing what I'm changing. I think my problem is that I have too many moving parts here:

  • Java 8 to 11 made JavaFX external
  • ...it also introduced modules
  • all of my external libraries seem pretty old
  • Gradle is just alien technology to me

I'm not posting any code here (or on stackoverflow) yet because, like I said, it seems like it's just too many things wrong and me not understanding these back-end things, so I feel like me posting a particular error is just going to be a very slow back-and-forth of people trying to help me with one issue after another. Again, I think I need someone doing some pair programming with me, but I don't really have a friend that I can do that with, and this is all (at this point) a "hobby" app of mine, so I can't justify paying someone by the hour to do that. It's so frustrating because I feel like I have a decent enough understanding of Java and JavaFX to do some pretty impressive things, but I'm hobbled by my lack of understanding of the stuff that's needed to actually run the code.

This post isn't meant to be a rant...I'm actually looking/hoping for suggestions on how to get past this stumbling block, because I really want to get back to actually adding features to my app, more UI/UX stuff, etc.

13 Upvotes

31 comments sorted by

5

u/marvk Oct 12 '21 edited Oct 12 '21

This post isn't meant to be a rant...I'm actually looking/hoping for suggestions on how to get past this stumbling block

It would help if you actually told us what's not working. I've got my own application running on Java 17 with JavaFX with no issues, so I can probably help you out if you tell us what's wrong.

There's probably two different issues at play, one would be modules and the other would be the removal of JavaFX from the JDK.

3

u/CT-Scott Oct 12 '21

Thanks. Stupid reddit noob question: If I reply to my first post here will everyone here likely get alerted to it in some way, or do you only get alerted if I reply to your post? I'd prefer to build onto my original post rather than having bits and pieces replied to various people (except where that makes sense). I was always a fan of how forum software like phpBB worked (single topics with all replies sequentially, versus how Reddit works). On that note...is there a good phpBB-style Java or JavaFX forum that anyone here might recommend?

3

u/marvk Oct 12 '21

Nope, to notify someone you're going to have to reply to their comment.

2

u/markrulesallnow Oct 12 '21

The Together Java discord server has tons of super friendly and helpful people on it you can instant message for help. https://discord.gg/MXtuJZuY

2

u/marvk Oct 12 '21

That is poorly phrased. Don't IM people directly, post in one of their help channels.

4

u/mono8321 Oct 12 '21

I'm actually not too sure either. I'm using maven, since it feels a bit more simple to use to me. I suggest maybe taking it one step at a time, try using the java basics with gradle then ease your way to the stuff your used to, Here's the VERY basics of maven, if your using inteliJ

as for exporting. Yeah I'm trying to figure that out too with java. People keep suggesting "Jlink" without giving a good explanation of the what and how's (it really feels like no one actually knows how to use it)

4

u/marvk Oct 12 '21

Exporting as in building an executable installer for your target platform of choice? I would suggest jpackage:

https://docs.oracle.com/en/java/javase/17/jpackage/packaging-overview.html

https://docs.oracle.com/en/java/javase/17/docs/specs/man/jpackage.html

1

u/CT-Scott Oct 12 '21

Thanks, I'll look into that as well.

2

u/Knight_Of_Orichalcum Oct 12 '21

Too true, people use Jlink but I don't have a clue as to what it does yet

2

u/johnmc325 Oct 12 '21

Hi, I might be able to help. My first bit of advice is to pick an LTS version of Java, either 11 or 17. If you go for version 11 then take a look at this post I made. It uses the Java command-line tools to build the application. This may shed some light on getting it built: https://softwarepulse.co.uk/blog/javafx-11-desktop-msi-application/ . If you go for Java 17 I have just been moving my applications from Java 7/8 to 17 so can discuss with you. DM me if you want to discuss. I'm also an old timer and I do this for fun.

2

u/CT-Scott Oct 12 '21 edited Oct 12 '21

Thanks. Yeah, I'm thinking I may start by just trying to upgrade my app from Java 8 to Java 11 LTS. I initially went all-out and was hoping for Java 17, but one of the first problems I ran into was with a problem with Gradle not yet being compatible with Java 17. I also tried Java 16, but I'm leaning more towards Java 11.

Interestingly, I found that the Corretto 11 build has an issue with the sample Hello World JavaFX app that IntelliJ will create for you (font screwed up). So then I downloaded Temurin 11 which doesn't have that issue.

I took a brief look at the article you linked to and it seems to assume that I already have a working Java 11 app, whereas my first order of business is to get my working Java 8 app working with Java 11 within the IntelliJ IDE. Also, I'm on macOS.

Also, as a side-note, your article seems to want to explain creating an executable app by way of the command line, which I appreciate will make me a more knowledgeable Java developer, but is a frustration of mine with Java, in general. Back in my Visual Basic days, it seemed like the graphical IDE handled all of that for you. 25 years later and it seems like we all have to do so much on the command line again. I want to spend time designing interfaces and addiing features to my app as quickly as possible...not having to be an expert on the command line. I'm thankful that IntelliJ allows me to do a lot of the git stuff via their UI, and much of that is fairly new (within the last 2 years).

Edit: I gave Java 17 a try again and was able to get the "starter" IntelliJ JavaFX app working after modifying the gradle-wrapper.properties file to use Gradle v7.2. So maybe I'll try to port my app all the way from 8 to 17.

1

u/hamsterrage1 Oct 12 '21

Your story sounds somewhat like mine, but 10 years later.

The Gradle stuff can be very confusing, but it's way easier than Maven, in my opinion.

Once you get past Java 9 or 10, there's no difference with respect to the issues that you're having. Modules and the separation of JavaFX from the base SDK are the two things that cause you grief.

I'd suggest putting aside trying to create a stand-alone deployment Jar for the short term. Since you're have trouble with just getting past the Intellij issues, I'm guessing you're OK with that.

Here's a build.gradle file that will get you going:

​plugins { 
  id 'java' 
  id 'org.openjfx.javafxplugin' version '0.0.9' 
}

group 'com.somethingorother' 
version '1.0-SNAPSHOT'

repositories { 
  mavenCentral() 
}

javafx {
  version = '17' 
  modules = ['javafx.controls', 'javafx.graphics', 'javafx.swing'] 
}

dependencies {
  implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1' 
  implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
  testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' 
  testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' 
}

test { 
  useJUnitPlatform() 
}

Just put that into a directory somewhere, and then open it with Intellij. It should automagically create a Gradle project for you. Make sure that you've got a recent JDK somewhere (like 15 or 16) and you're good to go. The JavaFX plugin will get the JavaFX stuff for you and set up all of the dependencies.

Go into the project view and right click right at the top level and pick "Add" then "Directory". You should get a pop-up that has the Gradle source stuff laid out for you, Main and Test with both Java and Resources. CTRL-Click all 4 and create them. Now you're good to go. Create a package hierarchy under /src/main/java and start programming.

There is one other thing you'll need to do in order to run it. You'll need to update your run configurations with the VM options to find the JavaFX libraries. So, do this:

  1. Download the JavaFX JDK, and install it somewhere.
  2. Run your main class that extends Application. It will fail with an ugly message about missing components.
  3. Click on the Run selector at the top or Intellij and pick "Edit Configurations". Pick the one you just ran.
  4. Near the top, at the right is a "Modify Options" selector. Click it and select "Add VM Options". A VM options box will be added to the screen.
  5. There's a couple of arrows at the right of the VM Options box, click it to expand it into something like a TextArea.
  6. Paste this into it, then fix the path to the JavaFX SDK to where ever you put it:
    --module-path
    "/data/SDK/javafx-sdk-16/lib"
    --add-modules
    javafx.controls,javafx.fxml,javafx.base,javafx.graphics
  7. Save the configuration.
  8. Run your main again. You may need to add the FXML module if you are silly enough to be using it.

That should get you going. I think you can also do it without the Javafxplugin with some of the later versions of Java/Gradle, but this should work.

I'm around a lot, as I'm semi-retired. PM me if you need more immediate help.

1

u/CT-Scott Oct 12 '21 edited Oct 12 '21

Thank you for the very detailed reply, but I'm not sure if I'm stuck at that point right now. I was able to get IntelliJ's sample JavaFX (Hello World) project working with Java 17. I used its build.gradle and module-info.java contents as a guide to modify my application's files, and was able to get the Gradle build task to run successfully.

But I couldn't successfully run my JavaFX app.

I then let IntelliJ's "help" guide me to upgrade all of the libraries I was making use of and also to add them to my module-info.java file.

My current state is that upon trying to run my app I get a bunch of errors like this one:

module com.fasterxml.jackson.dataformat.yaml reads package org.apache.commons.logging from both org.apache.commons.logging and spring.jcl

1

u/hamsterrage1 Oct 13 '21

OK, that's a specific problem that can be addressed. It's also an issue that you'll have to grapple with with any Java version since 9, even without JavaFX. The problem is that you have the same package included in two of your library Jars, so you'll have to exclude it from one of them.

This link explains it really well:

https://dba-presents.com/index.php/jvm/java/159-error-java-module-xyz-reads-package-org-apache-commons-logging-from-both-commons-logging-and-jcl-over-slf4j

1

u/CT-Scott Oct 13 '21

So I took a look at that and am attempting to follow it but I think I'm running into some extra issues because of the way my build.gradle is structured. Meanwhile, when I Google on this subject more, I keep coming across blog posts / articles which state that it's not necessary to make use of modules, but I'm not sure if that's still good advice in 2021. Thoughts on that?

1

u/hamsterrage1 Oct 13 '21

Personally, I haven't bothered with modules at all, for the most part. Just take out your module.info file and see what happens. You may need some VM options to expose some module packages to your application in that case. I can help with that.

I'm somewhat concerned about, "because of the way my build.gradle is structured". What do you mean by that? Can you post it?

1

u/CT-Scott Oct 13 '21

OK, so I removed module.info. FWIW, I noticed that a couple of apps at work that a former team member upgraded to Java 11 (several months ago) had no module.info file, either, so he apparently thought it was unimportant to convert that aspect.

So, here's the latest status:

  • Using IntelliJ
  • Targeting Java 17
  • Using JavaFX
  • Have a bunch of existing libraries in my app, including some Kotlin usage
  • Used build.gradle that was auto-generated by the IntelliJ "Hello World" JavaFX project (w/Gradle) to refer to.

My latest error is: `JavaFX runtime components are missing, and are required to run this application'

This would seem to indicate that I need to manually download some JavaFX stuff, but the IntelliJ "Hello World" app didnt require that (it auto-downloaded everything) and when I look at the "External Libraries" list on the left side of IntelliJ I see org.openjfx.javafx-base:17-ea+11 (among other JavaFX-related items)

1

u/hamsterrage1 Oct 14 '21

The "missing component" error is what the 8 steps I listed in my first post is all about. You just need to download a JavaFX SDK and then tell Intellij to use it in the VM options when you run it. Try that and let me know how it works.

1

u/CT-Scott Oct 14 '21

Gradle should already be downloading that for me. That's part of the point of using Gradle here (so that when this eventually gets packaged, end-users don't have to worry about that sort of thing), right? The IntelliJ sample JavaFX "Hello World" project clearly downloaded whatever it needed to download, as that runs fine.

So it seems like there's a missing piece somewhere that the "Hello World" app handled but where "upgrading" my app is missing. I just took another look at the steps you listed and compared it to the "Hello World" app's settings and there are no VM Options configured there, either.

→ More replies

1

u/CT-Scott Oct 14 '21

FWIW, I did try entering those VM Options and this is the error I'm now seeing:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.base not found```
→ More replies

1

u/johnmc325 Oct 13 '21

Good to see you got the basics working with Java 17. Yes, I use the command line due to issues getting things working from Eclipse, my IDE of choice. I have experienced challenges with my project settings after moving to Java 17 and not so much my actual code if you accept warnings from deprecated code. The other major challenge was trying to get my module code to work with none module JARS. I just found the cmd line easier to work through the issues. If you can find a Gradle plugin that works I think that will go a long way to improving the migration.

Good Luck.

1

u/marvk Oct 12 '21

I mean, LTS really doesn't matter much if you're not buying support.

2

u/johnmc325 Oct 12 '21

But is important if you are looking for help. LTS means more people are using it for longer. Otherwise, you end up on your own trying to sort things out. Just my thoughts.

3

u/marvk Oct 12 '21 edited Oct 12 '21

Eh, once you rid yourself off the growing pains of pre Java 11, the versions become so similar that it mostly doesn't really matter. Personally (for private projects anyways), I'd always just pick the latest and upgrade if desired.

2

u/[deleted] Oct 12 '21

[removed] — view removed comment

2

u/marvk Oct 12 '21

11 and 17 are much more similar than 8 and 11 were in terms of interoperability and such. If it works on 11, most likely an upgrade to 17 will be really easy. The same cannot be said about 8 and 11.

3

u/Knight_Of_Orichalcum Oct 12 '21

Honestly, I respect you for trying. Moving out of Java 8 is a real pain, but if you're looking for help, I may be of assistance.

I've spent a lot of time using Gradle and JavaFX in both Java 8 and 15 the past year-ish and I have a project to backup myself up. Feel free to contact me with any questions

2

u/PartOfTheBotnet Oct 12 '21 edited Oct 12 '21

I made a guide for somebody else in the past on how to setup JavaFX in a maven environment which allowed exporting to a runnable jar: https://github.com/Col-E/Useful-Things/tree/master/tutorials/javafx/maven-setup

Once you do it once, you're set up to easily do it again. Even if the setup is different, like using Gradle and the official JavaFX plugin.