Java program using a class from a JAR file

Posted by Myn on Stack Overflow See other posts from Stack Overflow or by Myn
Published on 2011-01-10T14:52:22Z Indexed on 2011/01/10 14:53 UTC
Read the original article Hit count: 172

Filed under:
|

Hi guys,

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;
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

© Stack Overflow or respective owner

Related posts about java

Related posts about jar