Java Class.forName() from distant directory
问题 I am currently loading Java classes using Class.forName() to load it. clazz = Class.forName("interfaces.MyClass"); But now I want to load classes from different directory, I have tried to set classpath by clazz = Class.forName("-cp \"C:/dir\" distantinterfaces.DistantClass"); With no success and ClassNotFoundException . Full path to distant class is: C:/dir/distantinterfaces/DistantClass.class 回答1: Use an URLClassLoader for this. The code might be something along the lines of: File f = new