aspose file tools*
The moose likes Java in General and the fly likes Invoke a Class from a Particular JAR file  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Invoke a Class from a Particular JAR file  " Watch "Invoke a Class from a Particular JAR file  " New topic
Author

Invoke a Class from a Particular JAR file

Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
I have a Class with under a package com.pkg.test which I have a Packaged as JAR file
say JAR1

----------------------JAR1-------------------------------------


--------------------------------------------------------------------

I have another JAR file with the same class name but differnt implemetaion and value of static variable
under same Package structure...Say

-------------------------JAR2---------------------------------------



---------------------------------------------------------------------------

Simalarly I have another JAR file with the same class under same Package structure...Say

-------------------------JAR3---------------------------------------



---------------------------------------------------------------------------




Now I create Another MainClass and import all these three JAR files into my class-path
(I included the JAR files in this order : JAR1,JAR2,JAR3)

--------------------------------------------------------------------------------------------



>>>>>>>>>>>>>>>>>>I get the following output>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Executing the project JARTest
Getting the Static variable T from ClassA
Value of T=1000
Calling printID method from ClassA
In Jar 1
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

If I include the JAR file in the following order :JAR3,JAR1,JAR2 ; then i get following output

Executing the project JARTest
Getting the Static variable T from ClassA
Value of T=222
Calling printID method from ClassA
In Jar 3


-------------------------------------------------------------------------------------------------

My question is how can we control this behaviour ,I mean how can we say to JAVA to use the ClassA
from the particular JAR file at runtime.My requiremnt is I need to access the methods of ClassA from
JAR1,JAR2 and JAR3.

Any Idea regarding this.

Thanks
Neel


Thanks & regards<br />Neel
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Instead of putting the jars onto the classpath, you'll need to use your own classloader(s).

Can you tell us more about where that requirement is coming from?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Consider Paul's rocket mass heater.
 
subject: Invoke a Class from a Particular JAR file