This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting classpath programmatically

 
Varun Nayudu
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to set classpath through a program in a web application or no.Please if there is then can you specify how.
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am inferring that you would like to set the classpath at Runtime. This can be done by making use of the properties class in Java. Please refer the javadoc for detailed information.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really? I had a look at the API documentation for java.util.Properties and it doesn't contain the phrase "classpath". Nor does it mention "class path".

But then, I don't believe you can set the classpath after it's initially been set by the JVM starting up. Not with the Properties class nor with anything else.
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
Really? I had a look at the API documentation for java.util.Properties and it doesn't contain the phrase "classpath". Nor does it mention "class path".

But then, I don't believe you can set the classpath after it's initially been set by the JVM starting up. Not with the Properties class nor with anything else.


Oops! My Bad. I misinterpreted the question. Monday mornings, I guess
;)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun,
I'm pretty sure the answer is no.

I'm going to move this to our Servlets forum since it has nothing to do with JDBC.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Varun Nayudu:
Is there a way to set classpath through a program in a web application or no.Please if there is then can you specify how.

If you want to change the JVM classpath so that every classloader can refer to, well properly "no". I've never tried that before.

But if you want to dynamically load a new class which is not in the current classpath, then yes, you can do it. All you need to do is to create a new classloader instance point to the classpath location of the class, then load that class with your new classloader.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic