Java version does not change in windows command prompt - java

I am trying to change my java version because of compiler errors when running mvn install via the windows command prompt.
I changed the JAVA_HOME variable and made sure that it is referenced in the PATH variable (##EDIT##: had been done like this %JAVA_HOME%\bin;%PATH%;).
When I open the command prompt in the folder where my pom.exe is located (using the Windows 7 'Open command window here' shortcut) and type java -version the unchanged java version is displayed.
I made sure to close all instances of command prompts before starting a new one.
Strangely I discovered that when starting the command prompt via the Run dialog in the start menu (by typing cmd) the result of java -version is the desired version.

You need to modify path variable as well as below:
PATH=%JAVA_HOME%/bin;%PATH%
Post that make sure you open a new command prompt and rerun maven command.

When using the 'Open command window here' shortcut make sure to close and open the respective explorer window. When starting the command prompt in this way Windows uses cached environment variables and does therefore not retrieve the current version of java.
Took me a while to figure out because it was too surprising to expect this behavior. Before I was searching on google and stackoverflow.com without any results. Hope this saves someone the trouble.

In my case worked the following: after editing the environment variables, and checking by command line java -version and javac -version, javac was updated but not java, so you have to do it by command line also
set path=C:\Program Files\Java\jdk1.8.0_181\bin

Remove the existing JRE setups..
Install the one that you need to install.
Hope you have added it in the environment variable and path via settings... Test it, it should work!.
The same thing happened to me long ago, It was pointing to the older JRE, got stuck, so removed the existing JDKs and installed a fresh copy. It worked.

I too faced this problem where I want to change the java version in command prompt but failed. But finally I succeeded doing the below steps. First I'll show the failed attempt, followed by the actual success step so you will know the difference.
Failed Step:
1. Win + R
2. Type cmd and hit enter
3. Type java -version (Just to check if the version is the old one which we need to change)
4. Now try changing the path/classpath using set path=/classpath=
5. Now again type java -version(This will still show the old java version but not the new version which we set)
Success Step:
1. Win + R
2. Type open command window here and hit enter
3. Type java -version (Just to check if the version is the old one which we need to change)
4. Now try changing the path/classpath using set path=/classpath=
5. Now again type java -version and voila I see the changed java version here
Thanks!

I had the same problem too. After setting the JAVA_HOME, i couldn't see the new value in command prompt even though I started a new command prompt.
Strangely, it only occured when opening the command prompt from the Windows Explorer.

I faced this issue too. I changed the JAVA_HOME in the environment variable and then when I opened cmd and typed java -version, I've seen older version. Then, I deleted javapath file in C:/Program Files/Common Files/Oracle/Java. My issue has been fixed in this way.

Related

Javac working with Powershell but not Command Prompt

I am trying to install Java in Windows 10 Home (64 bit). Like many tutorials point out, I downloaded the Java jdk setup file, executed it and once installed changed the Path in the Environment Variables. But for some reason, when I execute the command 'javac' it returns the not internal/external command error in Command Prompt but runs absolutely fine in Powershell. I tried to rectify this by uninstalling Java and reinstalling it very carefully, following all the steps but still this keeps on happening.
Also, during installation of Java, I lost the original value to my Path variable. Could this be causing the problem?
Edit : I was able to get the java command running in the command prompt but javac still won't work. I've already tried the methods suggested on other forums and this one but no luck so far.
See there is no problem with Java installation if you can find JDK(Java development kit) and JRE(Server Java runtime environment) in programme files in windows in a JAVA folder.
The main problem is with the environment variable declaration.
Go to environment variables and make a new path for that.
JAVA_HOME = "YOUR JDK & JRE INSTALLATION PATH"
And another one is
JAVA = "YOUR JDK & JRE INSTALLATION PATH"
Hope that help to you. After doing that if still there problem persisist just restart your PC and check again.
Just add your variable location up to /bin/
Refer to this :
https://www.windows-commandline.com/javac-not-recognized-internal-external-command/
Open file explorer
Right click computer then click properties
click advanced system settings
click environmental variables
click path (for me there was one in user variables for admin and another in system variables)
find the directory for javac (for me it was here C:\Program Files (x86)\Java\jdk1.8.0_191\bin)
so go back to file explorer and open program files x86
then open the java folder
then open the jdk folder
then open the bin folder
highlight the path in the search bar and copy it
click edit on path and paste into the path in the environmental variable for both(if you have more than one path)
If no path exists then create one in user variables
If there is any existing text place a semicolon ; between the text you pasted in there and the preexisting text.
close command prompt and reopen it.
type javac -version
the version info should be listed
This problem comes up with the directory of your command prompt.
check your PowerShell and command prompt default directory.
We can run command prompt as WinKey+R then type cmd, Hit the enter button then check our java version cmd javac -version.

Change system Java

I have 3 java in my system 1.6, 1.7 and java 8.
I set my JAVA_HOME and path to 1.7, but when I run java -version using cmd administrator mode it return me 8.
Could anyone please tell me from where cmd pick java, and how i can change it to another version.
Updated: I already set java 7/bin in path variable
Start your cmd shell and type echo %PATH%.
OS would inspect listed directories and the first one that has java binary will be the one being used.
To change it - the PATH variable is set based on the settings in Control Panel -> System -> Advanced System Settings -> Environment Variables. You'd need to start a new cmd session to see updated changes.
When we run cmd as an administrator then it pick java.exe which is already available under C:/user/windows32 folder.
To resolve this issue, instead of appending my java at the end of the path, append in the starting of the path vaiable.
So here is the code used in cmd if run as administrator
set path=%JAVA_HOME%/bin;%path%;
java -version

sourceanalyzer: command not found (mac)

I just installed a newer version of the Fortify package (4.30) but every time I try to use the command line to manually scan a project, I get an error that sourceanalyzer isn't an available option. I've tried reinstalling and I still cant get it to work. I can only scan in audit workbench. I never had this problem with earlier versions of Fortify.
Add this line to your ~/.bash_profile
alias sourceanalyzer="/Applications/HP_Fortify/HP_Fortify_SCA_and_Apps_4.xx/bin/sourceanalyzer"
Note: Where it says HP_Fortify_SCA_and_Apps_4.xx, put the version you are using here. Make sure your path is working and you shouldn't have to worry about it anymore. Don't forget to update this when you update your fortify application.
After this is done, just run the following command in your terminal:
source ~/.bash_profile
that will reload the bash_profile in your terminal.
Start /Applications/HP_Fortify/HP_Fortify_SCA_and_Apps_4.30/bin/sourceanalyzer
Open a new tab and run your fortify bash script or run sourceanalyzer command from here
It still will not run in my other terminal windows, but will only run in this one.
Is HP_Fortify/HP_Fortify_SCA_and_Apps_4.30/bin in your path system variable? For Windows, look at system properties, advanced, environment variables, then edit the PATH system variable and look for the entry for 4.30/bin.

Error: JAVA_HOME is not set and could not be found after Eclipse installation

Actually I installed hadoop successfully. hadoop version command worked fine. Now I wanted to run the map reduce program. So I installed eclipse. After which I am getting an error saying "Error: JAVA_HOME is not set and could not be found."
Even echo $JAVA_HOME command in cygwin terminal did not print the value after eclipse installation.
How can I fix this issue first?
How can I run the MaxTemperature map reduce program using eclipse.
Thanks
Try to set JAVA_HOME. You can do this by editing your env.sh such that it will have:
export JAVA_HOME=/absolute/path/to/your/java/home
In case the path contains spaces, surround it with double quotes.
Example:
export JAVA_HOME="/cygdrive/f/program files/java/jdk1.7.0_51"
You may need to refer to Eclipse Runtime Options.
I would try first to launch Eclipse with the -clean option
If that does not work, try launching Eclipse with -vm path to java vm
There are things you can do to modify the .ini file directly, but if these two fails, try to reinstall Eclipse. Remember, the java.exe exists in multiple locations on your PC. Changing your PATH variable manually might help you with Eclipse, but it may break other things. This is why some products use %JAVA_HOME% to distinguish from the Java that might be loaded before it.
If you want to really know what is going on with your Java installation, open a command prompt window and type c:\> where java.
As you can see, I have Java installed in multiple locations AND multiple versions of Java (7 and 8). It is important that you know these things before you start messing with environment variables.

Do I need to restart my system after setting JAVA in system environment's path variable?

I did the following steps but java does not seem to be working for me, do I need to restart my system if yes then why?
1. Right click My Computer->Advence Option->Environment Varibles->System Variables
2. variable : Path->Edit
3. Copy your jdk bin directory i.e.C:\Program Files\Java\jdk1.7.0_51\bin
4. Paste it after putting a semi-colon(;) in value section
i am getting below error while running java in cmd
C:\Users\User>java -version
Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
No, but you will need to close and recreate any cmd windows, running java programs, or the like.
To check it's correct, open a new cmd window and type set -> review the information for PATH and JAVA_HOME.
You should set two things:
JAVA_HOME
PATH
The first lies under the "User variables for [your user name]" section. Add the JAVA_HOME variable and set it to where your jdk is installed. i.e. C:\Program Files\Java\jdk1.7.0_51\
The second lies under the "System variables" section. You should find the "path" variable, and edit it. Then, append ";%JAVA_HOME%\bin" (minus the quotes) to the end of the path variable.
After you have done this, save the variables and close that window clicking the "ok" button. Close down all instances of the command prompt (and any IDE you may be developing with such as Eclipse or NetBeans), and reopen one command prompt. Then, if you would like to test whether or not your changes worked and are in effect, try the following:
echo %JAVA_HOME%
This should output where you set your java home variable to.
echo %PATH%
At the end of what is output, you should see your java home\bin addition to the path variable
java -version
If you can run this command from the command line, it means that your environment was set up correctly and java is now in your path.
Not necessary. Quit and Open the command prompt again (if any) that runs the java process and type java -version to check if it installed successfully.
If you are using mac, source ~/.bashrc or source ~/.zshrc should refresh your environmental variable. No need to re-start the terminal even.
No, you don't need to restart your system.
However, you have to restart your command prompt application to update the changes done on Environment variables.
NO.
You don't need to restart the system, but just the application like cmd or any IDE you are using for java development (i.e Eclipse) need to restart.
And to confirm that the java path is set that you have mentioned in JAVA_HOME environment variable, you can open cmd and you can check with commands echo %JAVA_HOME% or echo %PATH%.
I reinstall the JDK and set the JAVA_HOME and PATH variable again. now it's working.
In my case under user variable section(for particularuser) JAVA_HOME set to jre not jdk path . I change it to JDK path , It worked for me
yes need to restart cmd prompt after env variable change

Categories