Reputation: 261
I'm trying to migrate from java-1.8 to java-11.. I was facing the error "Missing JavaFX application class com.MainApp" and I looked for a solution online and found a couple of them:
https://openjfx.io/openjfx-docs/#modular
The above approach is to "create a new main class and call the main method of a class which extends application"
However, I'm still facing below issues:
I am running it through the command line and using the below commands:
1.Java -jar abc.jar
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:1016) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623) 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:521) at com.amx.rms.transporter.tools.config.MainDivert.main(MainDivert.java:7) Caused by: java.lang.ClassNotFoundException: javafx.application.Application at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 10 more
2.java --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules=javafx.controls,javafx.fxml,javafx.base,javafx.media,javafx.web,javafx.swing -jar abc.jar
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/Context at com.amx.rms.transporter.tools.config.MainDivert.main(MainDivert.java:7) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.Context at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 1 more
Below is my new main class:
public class MainDivert {
public static void main(String[] args) throws Exception {
try {
MainApp.main(args);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Not sure what I'm missing?
Upvotes: 0
Views: 1342
Reputation: 843
Your second approach looks quite promising. You already managed to add the JavaFX modules. So that's working. It seems, you have a couple of other libs you depend on, like logback. You'll have to add them to the classpath (or modulepath) as well.
Gradle can actually manage all the dependencies for you. You could start your app using gradle run
. See https://openjfx.io/openjfx-docs/#gradle
If you want to run the jar from the command line, you'll have to list all the dependencies in the classpath (module path) manually. This can be quite a pain.
Upvotes: 1