Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

java - Won't open runnable jar exported from eclipse Mac OS

I am running MacOS Big Sur (Intel MacBook Pro 2020) and I am using eclips for a college project.

The project is written with java and for GUI I am using JFX.

While using eclipse everything including the JavaFX code opens fine and runs.

When I am exporting the project to a runnable jar it asks to open it and then says there is an error .

On the other hand when my friends that are using windows are exporting to a runnable jar its working fine for them.

The project git is Here to watch

I tried to run it throw terminal to see the problem and I get the following message:

 rafaelelkoby@MacBook-Pro ~ % java -jar Server.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:151)
    at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:514)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:422)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:416)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:415)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:468)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:59)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 13 more

using java 8 JDK the JFX should be included so I can't really find the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So after the help From Slaw in the comments I figured out the problem and how to fix it.

My problem was that I was trying to execute a jar file using Java 15.0.1 witch doesn't work well with JavaFX.

At first check that you have Java 8 JDK installed.

And find the virtual machines folder witch in Mac is by default at the library folder under java folder.

Check you have a 1.8 version installed

Then check what is the java version executing the jar by the command:

java -version

Then if it is different then java 8 run the following:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Then run again and check that you are using java 8

java -version

Check that it has changed and run you're jar by using

java -jar JarName.jar 

If something is not clear please comment so I will change it.

Hope that I helped you :)

=======================================

Another option:

If you're code is using java 8

if the java -version is telling you that you are using something different then 1.8.X

On MacOS go to the virtual machine folder at /Library/Java/JavaVirtualMachines

and keep only the 1.8.X you use so it will be the default.

worked for me as well


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...