Right click My computer -> Advanced System Settings -> In Advanced tab go to Environment Variables -> Under User Variables Click over New button -> Input Variable name as Classpath -> Input Variable Value enter the path that you want to set up -> Click OK
Now restart the command prompt (If Opened already) and then check whether the classpath was set properly or not by entering a command
If you simply get '%Classpath%' as the result then you have set it wrong, The result should display the path that you set
You can give references to a variable of some other variable for sure but I don't think there is any way to set the System Variable using Java Language code. How would the process know the variable that you want to set, coz the process in which you would be setting path would also require the path of same variable. You can retrive those varibales if needed.
Please let me know if you are getting the what the issue is going to be, you could also use some batch file for the same I guess
Please mark the posts as Correct or helpful (if you indeed find those as correct or helpful )
Thanks and Regards
Hi iarpan , thanks for you reply. I was thinking that we can add system variable using JAVA but as you said it won't be possible then I tried to write a batch file as follow
But when I looked to path variable by going to environment variable window , i don't see the ''E:\MyWorkspace' appended to path variable . But if I echo path variable on cmd prompt it shows me the value appended to path variable. Please let me know where I am going wrong .
Conclusion: the set command you do in the command prompt is only for that instance of the command prompt and not for the entire machine. If you want to change the PATH system-wide, actually change it in the environmental variables window itself. I wouldn't know how to do that from a batch file and it certainly isn't possible from a Java application using plain Java code, its too Windows specific.
the command that you are using would set the path temporarily, for setting it permanently you need to go advanced system settings and change it from there
I guess your program would run error free even if you don't see the changes being reflected in your environment variables, am I correct Prem?