classloader example
This commit is contained in:
parent
f12497c18b
commit
2f31b4a8cc
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.classloader;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class SampleClassLoader {
|
||||
|
||||
public void loadClass() throws ClassNotFoundException {
|
||||
|
||||
System.out.println("Classloader of this class:"+SampleClassLoader.class.getClassLoader());
|
||||
|
||||
Class.forName("com.baeldung.classloader.SampleClassLoader", true
|
||||
, SampleClassLoader.class.getClassLoader().getParent());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.classloader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SampleClassLoaderTest {
|
||||
@Test(expected = ClassNotFoundException.class)
|
||||
public void givenAppClassLoader_whenParentClassLoader_thenClassNotFoundException() throws Exception {
|
||||
SampleClassLoader sampleClassLoader = (SampleClassLoader) Class.forName(SampleClassLoader.class.getName()).newInstance();
|
||||
sampleClassLoader.loadClass();
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue