The moose likes Java in General and the fly likes why System.setProperty donot work? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "why System.setProperty donot work?" Watch "why System.setProperty donot work?" New topic
Author

why System.setProperty donot work?

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 144
Dear ALL
i Want to use System.setProperty to set CLASSPATH
but i find it doesnot work. after run it,
CLASSPATH is same as before
below is code
before running java Test
classpath is null
after running java Test
classpath is still null,
How do i set classpath during program running time
and keep the change after running time?

import java.util.*;
public class Test
{
public static void main(String[] args)
{
System.out.println(System.getProperty("java.class.path"));

System.setProperty("java.class.path","C:\\C\\subc;"+System.getProperty("java.class.path"));
System.out.println(System.getProperty("java.class.path"));
}
}


public class Walter{
public boolean is_Working_Now(boolean is_boss_Coming){
return is_boss_Coming;
}
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

System properties and environment variables are not the same thing. And since envronment variables are a platform-dependent mechanism, Java doesn't have a supported means of accessing or setting them.
hth,
bear


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
In order to make a permanent change to the classpath on a Windows machine, you would have to interact with the Windows Registry, which would require finding the appropriate Microsoft dlls and using some JNI to invoke the correct methods.
Then you would do something similar for EACH target Operating System that you wanted to control.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
 
subject: why System.setProperty donot work?
 
Threads others viewed
problem in connecting to oracle through jdbc
Add classpath programmatically
How can I change classpath at runtime?
setting the path, classpath from within the java application
Current directory as a file address?
MyEclipse, The Clear Choice