Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Windows 7 I have added two user environment variables:

M2_HOME   %PROGRAMFILES%\Apache\apache-maven-3.0.2
M2        %M2_HOME%\bin

In my head, both of those should work, however, only the first one does for some reason. What I mean is that I in a command prompt can type

cd %M2_HOME%

Which works fine, but

cd %M2%

Which does not. What's going on here?

share|improve this question
    
Reboot.​​​​​​​​ –  Synetech Jun 30 '11 at 0:46

1 Answer 1

There seems to be a bug with nested environment variables in Windows 7 (maybe other versions too, I'm not sure) where if the name of the top level variable comes before the name of the nested variable alphabetically, it won't be expanded.

In your case, the top level variable M2 comes before the nested variable M2_HOME when sorted alphabetically. If you change M2 to something that comes after M2_HOME (eg, M3), you will see that it works as intended.

share|improve this answer
    
Now that's annoying... Guess that's also the reason why it doesn't work to add %M2% to the path as well. Any way to specify the order of these environment variables? –  Svish Jan 18 '11 at 8:44
    
The only way to get around the problem is to do what I said and rename M2 to something like M3 or even something like M2_PATH would work -- as long as it's something that comes after M2_HOME when compared alphabetically. Alternatively, you could edit M2_HOME and manually enter the program files directory instead of using %PROGRAMFILES%, as the bug only seems to occur when you have nesting of more than two levels. –  Herohtar Jan 18 '11 at 18:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.