I have the absolute path to a Java Class File. For this Class I need to find information like the methods/package information/ etc. Which is the cleanest and easiest way to do this. Can some one explain this or point to any examples?
The java.lang.Class class has methods in it for finding out all that information. To get the Class object of your class, look at the static Class.forName() method. It wants the name of a class that can be located on the classpath, however, and not an absolute path name. So, you'll have to make sure that the class file is accessible on the JVM's classpath by setting up it's location before you invoke the JVM.
Joined: Feb 12, 2002
So I assume I just need to set the classpath to the directory where the classfile is located and I do not need to know the package information right? suppose i have a class C:\Test\org\music\Guitar.class I set the classpath to C:\Test\org\music\ and then a Class c = Class.forName("Guitar") will give me a Guitar Class and c.getPackage().getName() will give me org.music ? if org.music is the package name? -- Thanks.