Discussion Locked

How To Get All Java PackagesIn Classpath

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do i get all the java packages in the classpath and get all the classes contained in the package at runtime. I need this because i have designed a small class browser and want to add a graphical display of packages in the classpath. The method in the java.lang.Package class doesn't give all the packages in the classpath.

3 replies

by penguinone!

You can get the class path by the following call:

String classPath = System.getProperty("java.class.path");

From there, you tokenize the string based on:

String classPathSeparator = System.getProperty("path.separator");

StringTokenizer tokenizer = new StringTokenizer(classPath, classPathSeparator, false);

Note that this will not only return directories, but also zip and jar files. If you want to display classes in those, check out java.util.zip and java.util.jar.Good luck!

This discussion is closed to new replies.