2

I'm working on setting up my development environment in Windows 7, installing Maven, etc. I've been running into path issues and have read, ad nauseum, other posts that pointed me in the right direction. My problem is, however, that my PATH variable (JAVA_HOME) isn't staying set.

When I try

mvn --version

I get

Error: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the location
of your Java installation.

So, I set it

set JAVA_HOME=C:\Tools\Java

and then mvn --version works. But if I close and then reopen the Windows terminal I just end up getting the original error. Super frustrating.

I've also added that path to the Environmental Variables in the Systems Settings (with the semi-colon spacing, etc) Path section.

4 Answers 4

3

You're only setting it within that shell. This is perfectly normal behaviour for environment variables - not just on Windows, but on other OSes too.

I don't know about Windows 7, but on Windows 8 if I press the Windows key and start typing "Environment Variables" I get an option to open the control panel applet for editing the user or system environment variables. That's where you want to put it. The right dialog looks like this:

Environment Variables dialog

If the method above doesn't get to it, you can use the System Properties dialog, which has a button near the bottom for it:

System properties dialog

Sign up to request clarification or add additional context in comments.

4 Comments

Oh, so I should specifically add JAVA_HOME itself to the user variables? I thought I just had to add it to the Path section.
If it's JAVA_HOME you're setting at the prompt, it's JAVA_HOME you want to set here, too.
@Matt: you may also want to add maven to your path, but the error message was telling you to set the JAVA_HOME environment variable, not PATH..
Yeah, that worked. I'll keep that in mind for Maven as well. Thank you, I had no idea I needed to set it in the User Variables section.
2

This is how the shell works in Windows, Mac OSX and UNIX and I suspect all operating systems.

Each prompt has it's own environment which is separate to any other process you have running. You can set a variable temporarily, but this is not saved to disk or preserved because you might set it in a script but you don't want it to affect the whole system.

If you want to change an environment variable in Windows you need to do Start -> Right Click Computer -> Properties -> Advanced Setting -> Environment Variables -> Add Property.

On Linux, you add your SET line to the ~/.bashrc file

Comments

0

To set environment variables in Windows, go to the System control panel (the quickest way is to right click Computer in the Start Menu and select Properties), and select Advanced system settings, and then Environment Variables...

1 Comment

Yeah, I've done that as well. I placed the full path (semi-colon spacing and appending \bin to the path as suggested in other posts), and still...same issue.
0

Go to System ->Advanced System Setting ->Environment Variables. In System Variables, Click on New and provide the Following:

Variable name as : JAVA_HOME

Variable Value as :E:/JdkInstallions/Jdk1.7 (as on my system)

This should resolve the problem you are getting.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.