Package is not a class. You cannot call Class.forName()
for package and access classes that belong to class using getDelcaredClasses()
.
I do not know what do you really need, so I'd recommend you to explain this in separate question. probably you will receive better solutions.
However if you really need this you have to do the following:
- Get your classpath by calling
System.getProperty(java.class.path)
- split this property to its elements by colon
- iterate over the list and read each resource. If resource is jar you can use ZipInputStream, if it is a directory use
File
class. - filter list of resources you got at #3.
Fortunately you can use 3rd party library named Reflections that helps you to do all this without writing code.