Java Class Find findClassLocation(Class context)

Here you can find the source of findClassLocation(Class context)

Description

find Class Location

License

Open Source License

Declaration

public static String findClassLocation(Class<?> context) throws IllegalStateException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;

public class Main {
    public static String findClassLocation(Class<?> context) throws IllegalStateException {
        String jarRelatedPath = "/" + context.getName().replace(".", "/") + ".class";
        URL location = context.getResource(jarRelatedPath);
        String jarPath = "";
        try {//from   www. ja va  2  s . com
            jarPath = URLDecoder.decode(location.getPath(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return jarPath.substring(0, jarPath.lastIndexOf("/") + 1);
    }
}

Related

  1. findClassBase(Class clazz)
  2. findClasses(String directory, String packageName)
  3. findClasses(String path, String packageName)
  4. findClassesAnnotatedWith(String packageName, Class a)
  5. findClassesAssignableFrom(String packageName, Class assignableFrom)
  6. findClassOriginFile(Class cls)
  7. getAllAssignedClass(Class cls)
  8. getAllClasses(ClassLoader cl, String packageName)
  9. getAllClasses(String packageName)