I'll try to phrase this as best I can. I have a program which has an API-like functionality - it uses reflection to dynamically call methods from within a class. In this instance:
Server.java
public static void main(String[] args) { Class<?> clazz = Class.forName("DiHandler"); StHandler out = (StHandler) clazz.newInstance(); out.read(); } DiHandler.java
// implements StHandler import edu.ds.*; public void read() { Ds aType = new Ds(); aType = "134"; } So DiHandler has a method read() which can contain anything, it doesn't matter to Server.java after compile time.
My problem is: DiHandler.java uses the class Ds from a JAR file. When I'm working on DiHandler.java in Eclipse (in a separate project from the project Server.java is in) I can add this JAR without a problem. But when I move DiHandler.class, after it's compiled, to be used by Server.class, how can it still use the JAR file?
I hope this makes some sense, I suppose another way to phrase it would be how can I allow DiHandler to call on a class from the JAR without editing the classpath?
Thanks very much in advance and sorry for any confusion or poor phrasing, I can only offer thanks and the customary offer of a pint for any assistance.
M
STHandler out = (StHandler) clazz;- I hope that's not actually how you're trying to instantiate anStHandler.