Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reflection/Class Loader question

Status
Not open for further replies.

greedyzebra

Technical User
Sep 5, 2001
140
0
0
US
Hi,

I'll try to simplify this problem as much as possible.

I have a program that uses multiple jar files. We'll call two of them 1.jar and 2.jar.

1.jar has objects w,x,y and z.
2.jar has objects y and z.

At runtime the user will decide whether to execute with 1.jar or 2.jar. I compile my program with 1.jar.

In my program I call Class.getMethod(String,Object[]), which crashes with a NoClassDefException.

In the error message is a reference to object w, which exists in 1.jar, but not 2.jar.

I have created a "dummy" jar that contains the classes that exist in 1.jar but not in 2.jar to run when the user uses 2.jar and it works. But I would like to find a way to solve this problem in a manner that would require less maintence (everytime a new version of 1.jar comes out, I'd have to see if there were new methods added).

Always willing to post further information if necessary, but don't want to make the description too long!
Thanks,
GZ
 
What's the reason for two different JARs?
Is 2.jar a restricted demo-version or something like that?

Are y and z identic in both JARs?

You don't have access to the source of 1.jar and 2.jar?

If your program should work with both JARs exclusively (either 1.jar OR 2.jar) you should ensure it's compiling with none of them, or if both contain the same (y, z), it should compile with 2.jar.

It's hard to see, what you're really trying to achive, and how to solve it.
Perhaps you may describe more concrete, what the difference is between 1 and 2, and what they have in common, and how your classes use them and why.

seeking a job as java-programmer in Berlin:
 
Well, you can define dinamycally the jars the classloader will use via the URLClassLoader class.

Anyway, you'll face problems if the classes in both jar are not compatible in its definition.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top