• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Modifying classpath dynamically

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Is there a way to modify CLASSPATH dynamically within a java program? What I want to do is load classes saved in another directory, currently not in the CLASSPATH.
Thanx,
Tom.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, no and yes.
No, you can't alter the CLASSPATH at runtime, but if you have a look at java.lang.ClassLoader you can load classes that are not on the class path at runtime.
Dave.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have'nt tried this myself. But probably you can..
System properties has a property
java.lang.path or something like that.
Am not sure about the key but you can list them out and check that.
try appending the new classpath there and then try accessing your class.
Properties prop = Syste.getProperties();
Enumeration e = prop.getPropertyNames();
...
prop.setProperty("java.lang.path","new classpath");
try this and let us know :-)
karthik.
 
Tom Diamond
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The correct name is "java.class.path" but it wouldn't work. I tried the following :

My Test2.class file is placed in D:/TempDir. It seems that the property does change but JVM is not aware of the change.
Anyway considering my problem, I've made a custom ClassLoader but I still have to load lots of class files so that I can invoke the main method of my application...
Tom.
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic