Any suggestions as to how to approach how I would find out a list of package names that exist on the current classpath?
This needs
This code will give you all classpath-entries (including the jre libraries):
String[] entries = ClassPath.getClassPath().split(";");
for (String entry:entries)
System.out.println(entry);
ClassPath is part of apache bcel and can be found as an internal (but usable) class in the jre (com.sun.org.apache.bcel.internal.util). AFAIK, the class is "internal" to avoid conflicts when a project requires the "real" bcel library.
You may want to filter the libraries of the JRE (they're included as this is the real classpath)
The next step would be looking at each (JarFile-)entry, visit all subdirectories (recursivly) and if (and only if) a directory contains at least one class file, the name of this directory (relative to the classpath entry) can be converted to a package name (example: META_INF is a directory in all jar files but not a package name...)