code_junkie

Find where java class is loaded from

Nov 11th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. package foo;
  2.  
  3. public class Test
  4. {
  5. public static void main(String[] args)
  6. {
  7. ClassLoader loader = Test.class.getClassLoader();
  8. System.out.println(loader.getResource("foo/Test.class"));
  9. }
  10. }
  11.  
  12. file:/C:/Users/Jon/Test/foo/Test.class
  13.  
  14. public static void String getClassResource(Class klass) {
  15. return klass.getClassLoader().getResource(
  16. klass.getName().replace('.', '/') + ".class").toString();
  17. }
  18.  
  19. getClass().getProtectionDomain().getCodeSource().getLocation();
  20.  
  21. MyClass.class.getClassLoader();
Add Comment
Please, Sign In to add comment