jus
jus

Reputation: 21

NoClassDefFoundError after changing from java8 to java 10

I have googled and searched the best I could, but I still could not find an solution. Maybe my search queries was not correct or details.

I do know there are a number of API changes from java 8 to 10. The jdk structure for 8 to 10 has also a significant changes.

Problem:

I have the following dependencies:
Project A --> Project B --> Project C

Some class in project A will call classes in Project B and B will call C. In Java 8 there were no issues.

After I upgrade to Java 10, a NoClassDefFoundError exception occurs.

I found two ways to overcome the issue

  1. Project A now also depends on Project C

  2. In the Java Build Path tab --> Order and Export tab, checked the Project C checkbox.

Question

  1. Is there a better way to resolve my problem instead of using the solutions I found? Because my project codes are huge and it will take a lot of time to do so.

  2. I would also like to know the underlying cause of the problem if possible.

Code:

ClassA.java (Project A):

package pkg;

public class ClassA {

    public ClassA() {
        new ClassB();
    }

    public static void main(String[] args) {
        new ClassA();
    }
}

ClassB.java (Project B)

package pkg;

public class ClassB {

    public ClassB() {
        callClassC();
    }

    public void callClassC() {
        ClassC classC = new ClassC();

        String info = classC.getInfo();

        System.out.println(info);

    }
}

ClassC.java (Project C)

package pkg;

public class ClassC {

    public String getInfo() {
        return "Class c info";
    }

}

I also exported a eclipse workspace for my issue. I created this workspace using an older version of eclipse and java.

Upvotes: 0

Views: 203

Answers (1)

Till Brychcy
Till Brychcy

Reputation: 2924

I can reproduce this. The code compiles, but you get an error when executing. This is an eclipse bug.

Please report it at https://bugs.eclipse.org.

A possible workaround: Edit the run configuration, go to the Dependencies tab, use Add variable string with the value ${project_classpath}

Upvotes: 2

Related Questions