1

I'm trying to make a cross-platform JavaFX application, and it works fine on Windows and OSX machines, but not on Linux.

When I try to run it on a Linux machine using java -jar app.jar, this is what I get:

Error: Could not find or load main class app.Main

But the class app.Main is in the .jar, as shown by 'jar tf app.jar':

...
app/Main.class
...

I tried specifying the main class using java -cp app.jar app.Main but I got the same error message.

The .jar was built in Intellij IDEA, using basic JavaFX configuration.

Any help?

Matheus Valin
  • 191
  • 2
  • 8
  • 2
    Which Java runtime do you have on the linux machine? OpenJDK does not ship with JavaFX. – James_D Mar 27 '17 at 20:06
  • 3
    [Which linux?](https://www.cyberciti.biz/faq/find-linux-distribution-name-version-number/), what Java version ([`java -version`])? Related: [Why is JavaFX is not included in OpenJDK 8 on Ubuntu Wily (15.10)?](http://stackoverflow.com/questions/34243982/why-is-javafx-is-not-included-in-openjdk-8-on-ubuntu-wily-15-10) and [JavaFX and OpenJDK](http://stackoverflow.com/questions/18547362/javafx-and-openjdk). See also [Oracle java distributions for Linux](http://www.oracle.com/technetwork/java/javase/downloads/index.html), which include JavaFX. – jewelsea Mar 27 '17 at 21:00

2 Answers2

1

So, turns out the problem was that the JRE on the Linux machine was OpenJDK, which does not come with JavaFX, as noted by James_D and jewelsea

After installing the oracle JRE 8, it worked fine

Matheus Valin
  • 191
  • 2
  • 8
0

Sorry for the necro post, but I had to take a few extra steps. I had JRE 8 installed, but I still had to point java_home to it. I'm using a MAC.

The JDK locations are here: /Library/Java/JavaVirtualMachines (verify this)

The default JDK for my machine was temurin-17.jdk

I had to change it to jdk1.8.0_301.jdk

Steps:

  1. Open a terminal
  2. Type: vim ~/.bash_profile
  3. I pasted this onto the file: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
  4. Save and exit vim: https://phoenixnap.com/kb/how-to-vim-save-quit-exit
  5. In the terminal, type: source ~/.bash_profile
  6. Restart your terminal
  7. In the terminal, type: java -version
  8. Make sure it's pointing to the right version
  9. Now navigate back to where the .jar is located.
  10. In the terminal, type: java -jar myapp.jar

Hope this helps.

Tim
  • 478
  • 4
  • 15
  • You are not really telling anybody to go back 11 versions of Java just because you are not able to get JavaFX working with the current version, do you? Instead have a look here for example: https://www.azul.com/downloads/?version=java-19-sts&os=macos&architecture=x86-64-bit&package=jdk-fx – mipa Oct 30 '22 at 08:46
  • Apologies sir, I meant to clarify this is for people who are still using JRE 8. The app I'm working on required JRE 8. But I'm thinking the steps should more or less be the same for more recent versions of Java? Anyway, sorry this didn't help you. – Tim Oct 31 '22 at 02:48