code: public static URL baseUrlOfClass(Class<?> clazz) {
          try {
              String name = clazz.getName();
              URL url = clazz.getResource("/" + name.replace('.', '/') + ".class");
              int curPos = 0;
              do {
                  curPos = name.indexOf('.', curPos + 1);
                  if (curPos >= 0) {
                      url = new URL(url, "..");
                  }
              } while (curPos >= 0);
              return url;
          } catch (MalformedURLException e) {
              throw new IllegalArgumentException("Invalid URL for class " + clazz.getName(), e);
          }
      }
docs: Returns the base URL of the specified class.
  <p>
  
  For example, if <code>java.lang.String</code> exists at
  http://base.net/parent/java/lang/String.class, the base URL
  is http://base.net/parent/.
  
  @param clazz the class.
  
  @return a base URL where the class is located.
  
  @throws IllegalArgumentException if a URL cannot be obtained.