Klassenliste des J2SDK API auslesen

RedWing

Erfahrenes Mitglied
Hallo,

gibt es in Java eine Möglichkeit die Klassenliste aller verfügbaren Klassen des API
auszulesen mit vollständigen Pfad (also java.lang.String) z.B.? Oder kennt
jemand eine Bibliothek mit der man des vielleicht realisieren koennte?

Danke und Gruß

RedWing
 
Hallo!

Schau mal hier:
Code:
 /**
   * 
   */
  package de.tutorials;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.jar.JarFile;
  import java.util.zip.ZipEntry;
  
  /**
   * @author daritho
   * 
   */
  public class SimpleAPIClassPrinter {
  
  	/**
  	 * @param args
  	 */
  	public static void main(String[] args) {
  		String bootClasspath = System.getProperty("sun.boot.class.path");
 		String[] bootClasspathEntries = bootClasspath.split(System.getProperty("path.separator"));
  		for (int i = 0; i < bootClasspathEntries.length; i++) {
  			String fileName = bootClasspathEntries[i];
  			if (!fileName.endsWith(".jar")) {
 			 System.out.println("Skipping: (NO JAR) " + fileName);
  				continue;
  			}
  
  			try {
  				File file = new File(fileName);
  				if (!file.exists()) {
 				 System.out.println("Skipping: (NOT FOUND)" + fileName);
 					continue;
  				}
  
 				JarFile jarFile = new JarFile(file);
  				printAllClassesOf(jarFile);
  			} catch (IOException e) {
  				e.printStackTrace();
  			}
  
  		}
  	}
  
  	private static void printAllClassesOf(JarFile jarFile) {
  		System.out.println("Classes for: " + jarFile.getName());
  		Enumeration entries = jarFile.entries();
  		while (entries.hasMoreElements()) {
  			ZipEntry entry = (ZipEntry) entries.nextElement();
  			String entryName = entry.getName();
  			if (entryName.endsWith(".class")) {
  				System.out.println(entryName);
  			}
  		}
  	}
  }

Gruss Tom
 
Ahja Danke Tom das ist genau das was ich gesucht habe...

String[] bootClasspathEntries = bootClasspath.split(";");

ersetzt durch

String[] bootClasspathJars = bootClasspath.split(System.getProperty("path.separator"));

dann funktionierts auch bei mir ;)

Danke und Gruß

RedWing
 
Okay, Done.
Btw. in Eclipse gibts eine Perspektive namens "Java Browsing" mit der kann man viel komfortabler durch die Bibliotheken Browsen ;)

Gruss Tom
 
Zurück