This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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
Pie
Posts: 20771
30
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: 34095
337
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