code: public static File getClassFile(Class<?> clazz) {
      File dir = new File(clazz.getProtectionDomain().getCodeSource().getLocation().getPath());
      if (!dir.isDirectory()) return null; // class file might be contained in Jar
      File clazzFile = new File(dir, clazz.getName().replace('.', File.separatorChar) + ".class");
      return clazzFile.isFile() ? clazzFile : null;
    }
docs: Returns the class file for the given class (which has been verified to exist in the returned location),
  or null if the class file could not be found (e.g. because it is contained in a Jar).