Link to home
Start Free TrialLog in
Avatar of garyshi
garyshi

asked on

How to set up classpath dynamically inside java class ??

Hi
I want to set up classpath inside java class dynamically. I have tried to use System.setProperty("java.class.path", "my class path string ") to set classpath dynamically. But it is not working. How to set it dynamically from java class ?? Thanks , gary
Avatar of nixj14
nixj14

You're in the same situation as I am in, so you may want to refer to the question that I will be asking.  To what I've researched and found from associates, you can not redefine a classpath once a VM has been instantiated.  You can however, define classes (or load classes) while the vm is loaded.  Look at the Classloader and System objects.


have you tried:
String cp = System.getProperty("java.class.path");
cp += ";new_jar.jar";
System.setProperty("java.class.path", cp);
Avatar of garyshi

ASKER

Hi nixj14,
Could you tell me main steps I should do for set classpath or load class ?? or If you have example code or few lines inportant codes for this problem, could you send them to me ?? Thanks so much.  I have to handle this problem as soon as possible. Otherwise I am worry ....

Venci75
I have tried the way you mention. It is not working.
Thanks all for you guy

Best Regards
Gary
gary2shi@yahoo.com
Avatar of garyshi

ASKER

Hi nixj14,
Thanks for giving me a link. But I can not open this link.  I guess it need a hotmail login first or it will check hotmail user, then go to some page. Could you copy them to me ?  Your hlep will be appreciated very much. Gary
ASKER CERTIFIED SOLUTION
Avatar of nixj14
nixj14

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of garyshi

ASKER

Hi nixj14,
Thanks for your help. I have run your example and it works fine.
Now I can load another class and run it from this classloader/example. But when I run one java class, it need some other java classes, like help.jar, util.jar. I have to put these jar files into classpath . There is no way to add these jar files into class path dynamically or use classloader to add these jar files into classpath ??  Again thanks for your help.
Gary
Yeah, I'm running through a similar problem.  I was able to download some good source to add jars into your classpath.

Try this

http://gcc.gnu.org/ml/java/2000-10/msg00002.html