Java Class from Package getClasses(String pckgname)

Here you can find the source of getClasses(String pckgname)

Description

get Classes

License

Open Source License

Declaration

@SuppressWarnings("rawtypes")
    public static List<Class> getClasses(String pckgname) throws ClassNotFoundException 

Method Source Code


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

import java.io.File;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Main {
    @SuppressWarnings("rawtypes")
    public static List<Class> getClasses(String pckgname) throws ClassNotFoundException {
        List<Class> classes = new ArrayList<Class>();
        ClassLoader cld = Thread.currentThread().getContextClassLoader();
        String path = '/' + pckgname.replace('.', '/');
        URL resource = cld.getResource(path);
        File directory = new File(resource.getFile());
        if (directory.exists()) {
            String[] files = directory.list();
            for (int i = 0; i < files.length; i++) {
                if (files[i].endsWith(".class")) {
                    classes.add(Class.forName(pckgname + '.' + files[i].substring(0, files[i].length() - 6)));
                }/*from   www  .  java2 s  .  c o m*/
            }
        }
        return classes;
    }
}

Related

  1. getClasses(String packageName)
  2. getClasses(String packageName)
  3. getClasses(String packageName)
  4. getClasses(String packageName)
  5. getClasses(String packageName, Class inheritedType)
  6. getClasses(String pckgname)
  7. getClasses(String pkg)
  8. getClasses(String pkg)
  9. getClassesForPackage(final String packageName)