문제

I am creating an Azure PaaS role which sets the PATH variable for java.exe . I have a background task which does that.

The startupApp.cmd looks like

    setx PATH %PATH%;%CD%\jdk\bin\  /m
    cscript /NoLogo util\unzip.vbs jdk.zip "%CD%"

Call the bat file to start my application. 

When the VM starts I see that the PATH environment variable is correctly set and points to where the jdk\bin folder. My application however fails to start with the error "java is not recognised as an internal or external batch command".

JAVA command to start my app is

java %JAVA_OPTS% %LOG_OPTS% %LOG4J_OPTS% -cp my_app.jar %MAIN_CLASS%

Here is the confusing path,

  1. After I log into the VM and open a command prompt window and type java I see that it works fine.
  2. If I restart the VM, the java command to bring up my app runs fine and I and my app too starts fine.
도움이 되었습니까?

해결책

There is a significant difference between setx and set function:

  • set takes effect in local cmd context. Meaning once you exit or close the cmd window, you lose the environment variable.

  • setx takes effect in future cmd context. So you won't see the environment variable and its value in the current cmd. You need to open a new cmd window to see it.

If you want to use it global and immediate you should use both functions side by side.

Description taken from: http://batcheero.blogspot.de/2008/02/set-and-setx.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top