0

I have downloaded an application on Ubuntu which requires JAVAFX and when i try to run the script.sh of the application it gives the following error

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at com.xiaomitool.miunlock.Main.main(SourceFile:46)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 10 more

I googled it a bit and found this post.The reason for my error is i have jdk11 installed on my ubuntu machine and javafx is available only till jdk8. But this post seems to be about compiling and running an application using JAVAFX. How do I run an already compiled program that requires JAVAFX? I tried adding the path of JAVAFX I downloaded i.e /openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib to the $PATH of my zsh and it dosent solve the problem. Could anyone please suggest what exactly is the issue with paths here and suggest a solution. Thanks in advance

Puce
  • 37,247
  • 13
  • 80
  • 152
Omnicacorp
  • 41
  • 7
  • 1
    You can find the documentation here: https://openjfx.io/openjfx-docs/#modular – Puce Mar 16 '21 at 09:54
  • Does this answer your question? [IntelliJ can't recognize JavaFX 11 with OpenJDK 11](https://stackoverflow.com/questions/52467561/intellij-cant-recognize-javafx-11-with-openjdk-11) – kleopatra Mar 16 '21 at 12:18

1 Answers1

0

I wanted to run a precompiled jar file and almost all the answers I could find were about compiling and running a jar file from source code and adding the modules as dependencies in the source code

here's the solution I found

download JavaFX Linux SDK from here then extract it to the desired location

then run export PATH_TO_FX=path/to/javafx-sdk-15.0.1/lib

then run the jar using

java -jar --module-path $PATH_TO_FX --add-modules {required modules seperated by commas} {path to jar file}

example

java -jar --module-path $PATH_TO_FX --add-modules javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web bin/Myapplication.jar

Omnicacorp
  • 41
  • 7