本文整理了Java中java.lang.Package.getPackages()
方法的一些代码示例,展示了Package.getPackages()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Package.getPackages()
方法的具体详情如下:
包路径:java.lang.Package
类名称:Package
方法名:getPackages
[英]Returns all the packages known to the caller's class loader.
[中]返回调用方的类加载器已知的所有包。
代码示例来源:origin: hawtio/hawtio
/**
* Returns all the classes found in a sorted map
*/
public SortedMap<String, Class<?>> getAllClassesMap() {
Package[] packages = Package.getPackages();
return getClassesMap(packages);
}
代码示例来源:origin: oracle/opengrok
Package[] p = Package.getPackages();
for(Package pp : p){
String pname = pp.getName();
代码示例来源:origin: hawtio/hawtio
public static Map<Package, ClassLoader[]> getPackageMap(List<ClassLoader> classLoaders, Set<String> ignorePackages) {
Map<Package, ClassLoader[]> answer = new HashMap<Package, ClassLoader[]>();
ClassLoader[] globalClassLoaders = {Thread.currentThread().getContextClassLoader(),
ClassScanner.class.getClassLoader()};
Set<Package> packages = new HashSet<Package>();
add(answer, Package.getPackages(), globalClassLoaders, ignorePackages);
ClassLoader[] classLoaderArray = new ClassLoader[classLoaders.size()];
classLoaders.toArray(classLoaderArray);
for (ClassLoader classLoader : classLoaders) {
Package[] loaderPackages = findPackagesForClassLoader(classLoader);
add(answer, loaderPackages, classLoaderArray, ignorePackages);
}
SortedSet<String> names = new TreeSet<String>();
for (Package aPackage : packages) {
names.add(aPackage.getName());
}
for (String name : names) {
LOG.info("Got package " + name);
}
return answer;
}
代码示例来源:origin: stackoverflow.com
public List<String> findPackageNamesStartingWith(String prefix) {
List<String> result = new ArrayList<>();
for(Package p : Package.getPackages()) {
if (p.getName().startsWith(prefix)) {
result.add(p.getName());
}
}
return result;
}
代码示例来源:origin: org.patterntesting/patterntesting-rt
/**
* Returns the packages which were loaded by the classloader.
*
* @return array with the loaded packages
*/
public Package[] getLoadedPackageArray() {
return Package.getPackages();
}
代码示例来源:origin: de.aosd.clazzfish/clazzfish-monitor
/**
* Returns the packages which were loaded by the classloader.
*
* @return array with the loaded packages
*/
public Package[] getLoadedPackageArray() {
return Package.getPackages();
}
代码示例来源:origin: IanDarwin/javasrc
public static void main(String[] argv) {
// BEGIN main
java.lang.Package[] all = java.lang.Package.getPackages();
for (int i=0; i<all.length; i++)
System.out.println(all[i]);
// END main
}
}
代码示例来源:origin: stackoverflow.com
Package[] ps = Package.getPackages();
for (Package p : ps) {
MyAno a = p.getAnnotation(MyAno.class)
// Recursively descend
}
代码示例来源:origin: stackoverflow.com
Package[] pa = Package.getPackages();
for (int i = 0; i < pa.length; i++) {
Package p = pa[i];
System.out.print("\"" + p.getName() + "\", ");
}
代码示例来源:origin: stackoverflow.com
MyObject myObject = null;
for (Package p : Package.getPackages()) {
try {
myObject = Class.forName(p.getName() + "." + className).newInstance();
break;
} catch (ClassNotFoundException ex) {
// ignore
}
}
代码示例来源:origin: stackoverflow.com
Package[] packages = Package.getPackages();
for (Package p : packages) {
MyPackageAnnotation annotation = p.getAnnotation(MyPackageAnnotation.class);
if (annotation != null) {
Class<?>[] implementations = annotation.implementationsOfPet();
for (Class<?> impl : implementations) {
System.out.println(impl.getSimpleName());
}
}
}
代码示例来源:origin: stackoverflow.com
public Collection<String> getPackages() {
Set<String> packages = new HashSet<String>();
for (Package aPackage : Package.getPackages()) {
packages.add(aPackage.getName());
}
return packages;
}
代码示例来源:origin: stackoverflow.com
final Package[] packages = Package.getPackages();
final String className = "ArrayList";
for (final Package p : packages) {
final String pack = p.getName();
final String tentative = pack + "." + className;
try {
Class.forName(tentative);
} catch (final ClassNotFoundException e) {
continue;
}
System.out.println(pack);
break;
}
代码示例来源:origin: com.github.Andy-Shao/Gear
public static Package[] getPckages(Package pkg) {
List<Package> result = new ArrayList<>();
Package[] packages = Package.getPackages();
for (Package ppkg : packages)
if (ppkg.getName().startsWith(pkg.getName())) result.add(ppkg);
return result.toArray(new Package[result.size()]);
}
代码示例来源:origin: com.github.Andy-Shao/Gear
public static Package[] getPackages(String regex) {
List<Package> result = new ArrayList<>();
Package[] packages = Package.getPackages();
for (Package pkg : packages)
if (pkg.getName().matches(regex)) result.add(pkg);
return result.toArray(new Package[result.size()]);
}
代码示例来源:origin: io.fabric8.forge/introspection
/**
* Returns all the classes found in a sorted map
*/
public SortedMap<String, Class<?>> getAllClassesMap() {
Package[] packages = Package.getPackages();
return getClassesMap(packages);
}
代码示例来源:origin: io.hawt/hawtio-util
/**
* Returns all the classes found in a sorted map
*/
public SortedMap<String, Class<?>> getAllClassesMap() {
Package[] packages = Package.getPackages();
return getClassesMap(packages);
}
代码示例来源:origin: io.atlasmap/atlas-java-inspect
public List<String> findChildPackages(String packageName) {
List<String> packageNames = new LinkedList<>();
Package originalPackage = Package.getPackage(packageName);
Package[] allPackages = Package.getPackages();
if (allPackages != null) {
for (Package tmpPackage : allPackages) {
if (tmpPackage.getName().startsWith(originalPackage.getName())) {
packageNames.add(tmpPackage.getName());
}
}
}
return packageNames;
}
代码示例来源:origin: com.github.Andy-Shao/Gear
@Override
public void process(String[] args) {
if (args.length < 2) throw new RuntimeException("args length is not enough");
for (String className : PackageOperation.getClasses(Paths.get(GeneralSystemProperty.JAVA_HOME.value() , "lib" , "rt.jar")))
if (className.matches(args[1])) System.out.println(className);
for (Package pkg : Package.getPackages())
for (String className : PackageOperation.getPackageClasseName(pkg))
if (className.matches(args[1])) System.out.println(className);
}
代码示例来源:origin: frenchc/jetm
ApplyToResolver() {
// preload packages
Package[] packages = Package.getPackages();
for (Package pkg : packages) {
registerApplyToIfAppropriate(pkg.getName(), pkg.getAnnotation(ApplyTo.class));
}
}
内容来源于网络,如有侵权,请联系作者删除!