code: public static String getClassPath(Class clazz){
          CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
          if(codeSource!=null)
              return URLUtil.toSystemID(codeSource.getLocation());
          else{
              URL url = clazz.getResource(clazz.getSimpleName() + ".class");
              if("jar".equals(url.getProtocol())){
                  String path = url.getPath();
                  try{
                      return URLUtil.toSystemID(new URL(path.substring(0, path.lastIndexOf('!'))));
                  }catch(MalformedURLException ex){
                      throw new ImpossibleException("as per JAR URL Syntax this should never happen", ex);
                  }
              }
              String resource = URLUtil.toSystemID(url);
              String relativePath = "/"+clazz.getName().replace(".", FileUtil.SEPARATOR)+".class";
              if(resource.endsWith(relativePath))
                  resource = resource.substring(0, resource.length()-relativePath.length());
              return resource;
          }
      }
docs: Returns the classpath resource(directory or jar) from which
  specified class is loaded.
  
  @param clazz class
  @return resource from which the class is loaded