Java Class from Package getClassNamesByPkg(String pkg)

Here you can find the source of getClassNamesByPkg(String pkg)

Description

get Class Names By Pkg

License

Apache License

Declaration

public static List<String> getClassNamesByPkg(String pkg) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.net.URL;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<String> getClassNamesByPkg(String pkg) {
        List<String> result = new ArrayList<>();
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        String packagePath = pkg.replace(".", "/");
        URL url = loader.getResource(packagePath);
        File dir = new File(url.getPath());
        for (File f : dir.listFiles()) {
            result.add(f.getName().replace(".class", ""));
        }/*from   w w  w.j  ava 2  s  . c o  m*/
        return result;
    }
}

Related

  1. getClassesInPackage(String packageName)
  2. getClassesInPackage(String packageName)
  3. getClassesInPackage(String pckgname)
  4. getClassesInPackage(String targetPackage)
  5. getClassNameByPackage(String packageName)
  6. getClassNamesForPackage(final Package p)
  7. getClassNamesFromPackage(String packageName)
  8. getClassNamesFromPackage(String packageName)
  9. getClassNamesFromPackage(String packageName)