This discussion is archived
13 Replies Latest reply: Aug 12, 2013 8:51 AM by rp0428 RSS

classpath problem

Prem Newbie
Currently Being Moderated

Hi ,

 

 

How can I create a system variable and put it's reference in 'path' environment variable ?

I searched on net but didn't find any helpful stuff. Please help me out.

 

Thanks'

  • 1. Re: classpath problem
    iarpan Newbie
    Currently Being Moderated

    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

    echo %Classpath%

     

    If you simply get '%Classpath%' as the result then you have set it wrong, The result should display the path that you set

  • 2. Re: classpath problem
    EJP Guru
    Currently Being Moderated

    You shouldn't need to do this. The classpath used by any specific application should be embedded in its JAR file.

     

    And if you're  asking about 'path' why is your question titled 'classpath'?

  • 3. Re: classpath problem
    rp0428 Guru
    Currently Being Moderated

    Close but the OP asked about 'path', not 'classpath'

    How can I create a system variable and put it's reference in 'path' environment variable ?

  • 4. Re: classpath problem
    iarpan Newbie
    Currently Being Moderated

    Thanks for bringing to my notice rp0428, Beg a Pardon to all for the mistake

     

    Can replace the word 'classpath' with the word 'path' (wherever the word classpath appears) in the earlier answer

     

    Sorry again for the mistake

     

    Thanks and Regards

    Arpan

  • 5. Re: classpath problem
    Prem Newbie
    Currently Being Moderated

    Ok.. I can do this now. Thanks . But one more question , Can I create a system variable using java language and put it's reference in 'path'?

  • 6. Re: classpath problem
    iarpan Newbie
    Currently Being Moderated

    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

    Arpan

  • 7. Re: classpath problem
    Prem Newbie
    Currently Being Moderated

    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

     

    SET path=%PATH%;E:\MyWorkspace

     

    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 .

  • 8. Re: classpath problem
    gimbal2 Guru
    Currently Being Moderated

    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.

  • 9. Re: classpath problem
    Prem Newbie
    Currently Being Moderated

    So how other application like oracle directly access path variable and set its path .

  • 10. Re: classpath problem
    gimbal2 Guru
    Currently Being Moderated

    Native code perhaps?

  • 11. Re: classpath problem
    iarpan Newbie
    Currently Being Moderated

    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?

  • 12. Re: classpath problem
    Prem Newbie
    Currently Being Moderated

    But is there any way to set a path without going to that window ? Any language in which I can write that code ?

  • 13. Re: classpath problem
    rp0428 Guru
    Currently Being Moderated

    Prem wrote:

     

    But is there any way to set a path without going to that window ? Any language in which I can write that code ?

    Use the SETX command. It is part of Vista and later OSs. For an earlier OS you can find it in the Windows Server 2003 Resource Kit Utilities.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points