This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
loading class from different path
Posted by Pavan Kumar Keely on January 21, 2002 at 3:56 AM
> hi, i hope somebody help me...
> how i could load a class that is in a directory diferent to the main....
> for example:
> if the main is in c:\main
> and the class is in c:\another
> thanks a lot...
You can load the classes dynamically from any path, if you can read the file (class file). The procedure is as follows...
I am giving a simple program which will do this...
public class ScriptExecutionManager extends ClassLoader
public void executeScript(String fileWithPath)
File file = new File(fileWithPath);
FileInputStream fis = new FileInputStream(file);
int available = fis.available();
byte bytes = new byte[available];
Class scriptClass = this.defineClass("Script",bytes,0,bytes.length);
netpod.liveupdate.ScriptInter script = (netpod.liveupdate.ScriptInter)scriptClass.newInstance();
script = null;
scriptClass = null;
// for debugging purpose
public static void main(String s)
If you can't understand this...please do mail me to email@example.com...