0

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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jus
  • 21
  • 1
  • 1
    Please post a [mcve]; the absence of a practical example to illustrate this question makes it hard to come up with an answer to this. For example the problem might be one of using JAXB (which is no longer loaded by default, and will be removed in Java 11, iirc), or maybe something else entirely. – Mark Rotteveel May 15 '18 at 15:27
  • There is a minimal code example on the post, but be sure to have each class in a separate project – jus May 16 '18 at 01:08
  • 1
    Eclipse projects have no relevance to Java, regardless of which Java version you are using. Perhaps you forgot to mention that you also changed the Eclipse version when migrating, as what you describe, is merely an Eclipse configuration problem. – Holger May 16 '18 at 09:10
  • Possible duplicate of [transitive dependencies in Eclipse Plugin-Project with Java 9](https://stackoverflow.com/questions/49479262/transitive-dependencies-in-eclipse-plugin-project-with-java-9) – Madjosz Aug 02 '18 at 19:19

1 Answers1

2

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}

Till Brychcy
  • 2,876
  • 1
  • 18
  • 28