BAEL-831 ClassNotFoundExceptions vs NoClassDefFoundError (#1899)
* Dependency Injection examples Dependency Injection examples for evaluation article * Junit test cases added for dependency injection Junit test cases added for dependency injection * ClassNotFoundException vs NoClassDefFoundError Example to reproduce ClassNotFoundException & NoClassDefFoundError * JUnit test cases for ClassNotFoundException & NoClassDefFoundError test cases to reproduce ClassNotFoundException & NoClassDefFoundError * Deleting exampls for evaluation article * BAEL-831 Examples for ClassNotFoundException & NoClassDefFoundError * deleting config file for evaluation article deleting config file for evaluation article
This commit is contained in:
parent
45e16d409b
commit
28adbeb53d
@ -0,0 +1,7 @@
|
|||||||
|
package com.baeldung.classnotfoundexception;
|
||||||
|
|
||||||
|
public class ClassNotFoundExceptionExample {
|
||||||
|
public void loadDrivers() throws ClassNotFoundException {
|
||||||
|
Class.forName("oracle.jdbc.driver.OracleDriver");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.baeldung.noclassdeffounderror;
|
||||||
|
|
||||||
|
public class ClassWithInitErrors {
|
||||||
|
static int data = 1 / 0;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.noclassdeffounderror;
|
||||||
|
|
||||||
|
public class NoClassDefFoundErrorExample {
|
||||||
|
public ClassWithInitErrors getClassWithInitErrors() {
|
||||||
|
ClassWithInitErrors test;
|
||||||
|
try {
|
||||||
|
test = new ClassWithInitErrors();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
System.out.println(t);
|
||||||
|
}
|
||||||
|
test = new ClassWithInitErrors();
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.classnotfoundexception;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ClassNotFoundExceptionTest {
|
||||||
|
|
||||||
|
@Test(expected = ClassNotFoundException.class)
|
||||||
|
public void givenNoDriversInClassPath_whenLoadDrivers_thenClassNotFoundException() throws ClassNotFoundException {
|
||||||
|
ClassNotFoundExceptionExample test = new ClassNotFoundExceptionExample();
|
||||||
|
test.loadDrivers();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.noclassdeffounderror;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class NoClassDefFoundErrorTest {
|
||||||
|
|
||||||
|
@Test(expected = NoClassDefFoundError.class)
|
||||||
|
public void givenInitErrorInClass_whenloadClass_thenNoClassDefFoundError() {
|
||||||
|
NoClassDefFoundErrorExample sample = new NoClassDefFoundErrorExample();
|
||||||
|
sample.getClassWithInitErrors();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user