RuntimeUtil { public static String classLocation(Class<?> clazz) { if (clazz == null) { return null; } ProtectionDomain domain = clazz.getProtectionDomain(); return (domain.getClassLoader() != null) ? domain.getCodeSource().getLocation().getPath() : clazz.getName(); }  static String currentClassMethod(); static String currentMethodName(); static String currentClassName(); static String currentNamespace(); static String classLocation(Class<?> clazz); static String classLocation();  }
@Test public void classLocation() { File file = new File(RuntimeUtil.classLocation()); String classLocation = file.getAbsolutePath(); file = new File(ClassLoaderUtil.getClasspath()); String classpath = file.getAbsolutePath(); String target = StringUtil.substringBeforeLast(classpath, File.separator); assertEquals(target + File.separator + "classes", classLocation); assertNull(RuntimeUtil.classLocation(null)); assertEquals("java.lang.String", RuntimeUtil.classLocation(String.class)); logger.info(RuntimeUtil.classLocation(StringUtil.class)); }