I am installing Maven and need to set M2 and M2_Home. I have set them in the user variables in Environment variables. And I added ;%M2% to the Path variable in the System variables in Environment variables. I was expecting to be able to run mvn --version but I couldn’t. However if I do
echo %Path% I can see that there is %M2% in the Path and if I echo %M2% I can see the bin directory that mvn is in.
So I had this problem. The problem did not get solved until I created a Path variable in user variables and added %M2% to that one (and removed it from the path in System variables). Now it works. Does any one know why it is only working in this specific way?
You’d have to look at the Windows source code to be certain what’s going on, but this doesn’t surprise me. Based on my testing, it appears that system environment variables can only reference other system environment variables, not user environment variables.
Note that
echo %PATH%should show the expanded path. You shouldn’t see%M2%.This is probably because system environment variables sometimes need to be expanded in situations where there is no user context. If user environment variables were included in the expansion of system environment variables this would need to be treated as a special case. It’s also possible that this was considered the preferred behaviour so that a user’s environment variables couldn’t unexpectedly affect the interpretation of system variables, or that there are issues related to the way environment variables are inherited between processes.
Either add
%M2%to the user path as you’ve done, or makeM2a system rather than a user environment variable.