0

I exportet a Jar of a JavaFX2 Project. It works fine, but when I run it on another machine there will be a classDefNotFoundExeption: javafx.application.Application

Any hints how to tackle this Problem ?

This is my Manifest:

Class-Path: .
Main-Class: proj.view.Launcher

I also programmed Launcher that starts a Swing GUI in case JavaFX is not found.

Here is my Launcher Class


public class Launcher {

    public static void main(String[] args) {

        try {

            Class c = javafx.application.Application.class;
            proj.main.App.main(args);


        }catch (NoClassDefFoundError e) {
            String[] t = {"Swing Backup","Application start Error"};
            MainFrame.remote(t);


        }

    }

}


Luxusproblem
  • 1,913
  • 11
  • 23
  • After a bit of thought. I think I would first check the version of java that is installed on the other machines. `java -version`. JavaFX 2.0 isn't super new, but it is only in Java 8 and beyond. It wouldn't surprise me to see some pretty old version of the Java JRE still out there in the wild. – hooknc May 28 '19 at 16:47
  • is `1.8._051` jdk of your machine or jdk of machine you are getting exception ? please provide details of jdk on both the machines.. – Babu Sekaran May 28 '19 at 16:47
  • jdk1.8.0_051 works fine. But on the other machine it's : jdk1.8.0_181 @Babu Sekaran – Luxusproblem May 28 '19 at 17:01
  • @Luxusproblem It shouldn't be failing for `jdk1.8.0_181`, but can you try building after adding the dependency I have mentioned in my answer. – Babu Sekaran May 28 '19 at 17:06
  • @hooknc but it compiles in the Eclipse-IDE of the other Machine. And works fine. Only the Jar wont work with FX. – Luxusproblem May 28 '19 at 17:06

4 Answers4

3

The other computers are running on a Java installation that doesn't include JavaFX. It works on your machine because you do have JavaFX installed.

To test if javafx.application.Application is available, you need to use reflection, i.e.

boolean hasJavaFX;
try {
    Class.forName("javafx.application.Application");
    hasJavaFX = true;
} catch (ClassNotFoundException e) {
    hasJavaFX = false;
}
if (hasJavaFX) {
    MainFrame.remote(new String[] {"Swing Backup","Application start Error"});
} else {
    proj.main.App.main(args);
}
Andreas
  • 154,647
  • 11
  • 152
  • 247
0

You might get classDefNotFoundExeption: javafx.application.Application when you are running on machine having jdk above 11.

oracle has removed javaFX form JDK 11, hence need to provide dependency on javafx-controls module.

`<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>12-ea+9</version>
</dependency>`

add this to your dependency.

https://openjfx.io/

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
0

To me it looks like runnable jar issue if then same code is working through IDE's on those machines. You can try maven assembly plugin to pack your jar.

The Apache Maven Assembly Plugin allows users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single, runnable package.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <archive>
                <manifest>
                    <mainClass>
                        package.your_main_class
                    </mainClass>
                </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </execution>
    </executions>
</plugin>
Sandeep Kumar
  • 13,799
  • 21
  • 74
  • 110
0

I figured it out: It was the User Path variable that pointed to a JDK10 bin.

We changed the Path. Now it works with "java -jar programm.jar" but not with "java programm.jar"

but not with a Regular click on the file. But we wrote a batchFile that Starts the Application with "java -jar" and it works fine.

Has anyone a explanation for that behavior ?

Luxusproblem
  • 1,913
  • 11
  • 23