aspose file tools*
The moose likes Servlets and the fly likes Setting classpath programmatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting classpath programmatically" Watch "Setting classpath programmatically" New topic
Author

Setting classpath programmatically

Varun Nayudu
Ranch Hand

Joined: Jun 26, 2006
Posts: 157
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.


SCJP 1.5, SCWCD 1.5
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
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.


SCJP 1.4 85%
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

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

Joined: Feb 14, 2006
Posts: 210
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
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.


“Everything should be as simple as it is, but not simpler.” Albert Einstein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting classpath programmatically
 
Similar Threads
Running application from command mode (MS DOS WINDOW)
Web Application Architecture
class 1
how to use ClassLoader ???
Compiling, but not running !!!