Your class has a reference to the class Din the method public void omg(D d).
Usually, the Sun / Oracle JVM uses lazy resolution, so it doesn't matter if you don't use this method, however you can see from the stack trace that the main method is executed using a reflexive operation Class.getMethodthat makes the difference.
You can verify this with the following code:
public class B {
public static void main(String[] args) {
D.main(args);
}
}
class D {
public void foo(E e) {}
public static void main(String[] args) {
System.out.println("hello world");
}
}
class E { }
E.class java B . :
public class B {
public static void main(String[] args) {
try {
D.class.getMethod("main", String[].class);
} catch(NoSuchMethodException ex) {
ex.printStackTrace();
}
D.main(args);
}
}
class D {
public void foo(E e) {}
public static void main(String[] args) {
System.out.println("hello world");
}
}
class E { }
, E , java.lang.NoClassDefFoundError: E java B. , , , D main.
, , public foo. , Class.getMethod public .
: public omg NoClassDefFoundError.