Alejandro Narancio wrote:
Hi for everyone, i'm trying to make reflection to a .class or a .java
java file, anybody know how can i obtain a Class instance from a file?
Thks and regards,
Alejandro
If you have a .class file, the easiest way is to make sure that the
..class file is in the proper location in the CLASSPATH. Then the
default system class loader will find the class and you can just use it.
If the name of the class is determined dynamically, use the
Class.forName() method. This technique is employed to load JDBC drivers,
for example.
If it is not possible to include the .class file in the CLASSPATH, you
need to write a custom ClassLoader. Read the file into a byte array and
invoke the ClassLoader.defineClass() method.
If all you have is a .java file, you need to invoke some sort of
compiler (AFAIK, a compiler is not included with the JRE) to create a
..class file and use one of the above techniques.
HTH,
Ray
--
XML is the programmer's duct tape.