can't install R package due to java error [duplicate] - java

I went to the Environment Variables in 'System' in the control panel and made two new variables, one for user variables and one for system variables. Both were named JAVA_HOME and both pointing to
C:\Sun\SDK\jdk\bin
But for some reason, I still get the below error when running a Java command...
BUILD FAILED
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:161: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:141: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:137: Please set java.home to a JDK installation
Total time: 1 second
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish>lib\ant\bin\ant -f setup.xml
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: setup.xml
How can I fix this problem?

Find JDK Installation Directory
First you need to know the installation path for the Java Development Kit.
Open the default installation path for the JDK:
C:\Program Files\Java
There should be a subdirectory like:
C:\Program Files\Java\jdk1.8.0_172
Note: one has only to put the path to the jdk without /bin in the end (as suggested on a lot of places). e.g. C:\Java\jdk1.8.0_172 and NOT C:\Java\jdk1.8.0_172\bin !
Set the JAVA_HOME Variable
Once you have the JDK installation path:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab, then click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
Click Apply Changes.
Note: You might need to restart Windows
The complete article is here, on my blog: Setting JAVA_HOME Variable in Windows.

What worked for me was adding the %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.

You have to first Install JDK in your system.
Set Java Home
JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location of your JDK Installation Directory]
Once you have the JDK installation path:
Right-click the My Computer icon on
Select Properties.
Click the Advanced system setting tab on left side of your screen
Aadvance Popup is open.
Click on Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
Click Apply Changes.
Set JAVA Path under system variable
PATH= C:\Program Files\Java\jdk1.7.0; [Append Value with semi-colon]

In cmd (temporarily for that cmd window):
set JAVA_HOME="C:\\....\java\jdk1.x.y_zz"
echo %JAVA_HOME%
set PATH=%PATH%;%JAVA_HOME%\bin
echo %PATH%

You need to set it to C:\Sun\SDK\jdk (Assuming that is where the JDK is installed - It is not the default) - Do not put the \bin in C:\Sun\SDK\jdk\bin.
If your app only runs when you are logged in as the current user then put it in the user variables - If it needs to run for all users on your system then put it in System variables.
You might also need to add %JAVA_HOME%\bin to the path also (Also it depends on whether you run it from just the user or from all users, including System)

http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html
Control Panel > Java, Java tab, click the View button. In Runtime Parameters, put:
-Djava.home=YOUR_PATH_HERE
Or when you execute Java you can add that command line switch to the command:
java -Djava.home=PATH SomeJavaApp

One Image can fix this issue.
For More

For those who are still stumped with this problem (I tried all the above suggestions) --
If you're on a 64-bit version of Windows and you've installed the 32-bit JDK, besides adjusting PATH variables, you may need to adjust registry variables, too.
I was pulling my hair out, having correctly set my PATH variables -- still to no avail -- and then only finding "vacated" Java entries in my registry, seemingly a deadend of fixing the "misfiring" Java Runtime Environment.
By using Process Monitor to watch the program I was trying to get started, in order to sniff out where it was looking in the registry for Java (Runtime Environment), I triumphantly discovered that it's looking in the 32-bit version of registry entries, found in HKEY_LOCAL_MACHINE\SOFTWARE\**Wow6432Node**\JavaSoft\Java Runtime Environment.
Within that key, you should find subkeys of different Java versions installed (past and/or present). Click on the subkey of the latest version (my subkey is currently 1.7.0_25, for example). After clicking on that subkey, you'll see registry string values listed on the right, and particularly, JavaHome and RuntimeLib. You need to modify the values of those two values to reflect the both the current folder and jvm.dll file, respectively.
For example, in my case, the values were (previously) respectively set at C:\Program Files (x86)\Java\jre7 and C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll which are nonexistent on my machine. I had to update these to the current folder and file of C:\Program Files (x86)\Java\jdk1.7.0_25\jre and C:\Program Files (x86)\Java\jdk1.7.0_25\jre\bin\client\jvm.dll.
Again, this will depend entirely on both what version of Java (JDK and/or JRE) you have installed -- 32 or 64-bit -- and what type of operating system you're on -- 32 or 64-bit. Just know that they're reflected in different locations within the registry (like the Wow6432Node for 32 bit applications, in my case with the 32-bit JDK installed on a 64-bit machine).
Now that I've updated those two registry values, my program runs flawlessly, with no more hiccups or complaints about a missing Java Runtime Environment (stemming from the registry).

This is the official solution for setting the Java environment from www.java.com - here.
There are solutions for Windows 7, Windows Vista, Windows XP, Linux/Solaris and other shells.
Example
Windows 7
Select Computer from the Start menu
Choose System Properties from the context menu
Click Advanced system settings -> Advanced tab
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Reopen Command prompt window, and run your Java code.

Windows 7
Go to Control Panel\All Control Panel Items\User Accounts using Explorer (not Internet Explorer!)
or
click on the Start button
click on your picture
Change my environment variables
New...
(if you don't have enough permissions to add it in the System variables section, add it to the User variables section)
Add JAVA_HOME as Variable name and the JDK location as Variable value > OK
Test:
open a new console (cmd)
type set JAVA_HOME
expected output: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60

We need to make a distinction between the two environment variables that are discussed here interchangeably. One is the JAVA_HOME variable. The other is the Path variable. Any process that references the JAVA_HOME variable is looking for the search path to the JDK, not the JRE. The use of JAVA_HOME variable is not meant for the Java compiler itself. The compiler is aware of its own location. The variable is meant for other software to more easily locate the compiler. This variable is typically used by IDE software in order to compile and build applications from Java source code. By contrast, the Windows CMD interpreter, and many other first and third party software references the Path variable, not the JAVA_HOME variable.
Use case 1: Compiling from CMD
So for instance, if you are not using any IDE software, and you just want to be able to compile from the CMD, independent of your current working directory, then what you want is to set the Path variable correctly. In your case, you don't even need the JAVA_HOME variable. Because CMD is using Path, not JAVA_HOME to locate the Java compiler.
Use case 2: Compiling from IDE
However, if you are using some IDE software, then you have to look at the documentation first of all. It may require JAVA_HOME to be set, but it may also use another variable name for the same purpose. The de-facto standard over the years has been JAVA_HOME, but this may not always be the case.
Use case 3: Compiling from IDE and CMD
If in addition to the IDE software you also want to be able to compile from the CMD, independent of your current working directory, then in addition to the JAVA_HOME variable you may also need to append the JDK search path to the Path variable.
JAVA_HOME vs. Path
If your problem relates to compiling Java, then you want to check the JAVA_HOME variable, and Path (where applicable). If your problem relates to running Java applications, then you want to check your Path variable.
Path variable is used universally across all operating systems. Because it is defined by the system, and because it's the default variable that's used for locating the JRE, there is almost never any problem running Java applications. Especially not on Windows where the software installers usually set everything up for you. But if you are installing manually, the safest thing to do is perhaps to skip the JAVA_HOME variable altogether and just use the Path variable for everything, for both JDK and the JRE. Any recent version of an IDE software should be able to pick that up and use it.
Symlinks
Symbolic links may provide yet another way to reference the JDK search path by piggybacking one of the existing environment variables.
I am not sure about previous versions of Oracle/Sun JDK/JRE releases, but at least the installer for jdk1.8.0_74 appends the search path C:\ProgramData\Oracle\Java\javapath to the Path variable, and it puts it at the beginning of the string value. This directory contains symbolic links to the java.exe, javaw.exe and javaws.exe in the JRE directory.
So at least with the Java 8 JDK, and presumably the Java 8 JRE standalone, no environment variable configuration needs to be done for the JRE. As long as you use the installer package to set it up. There may be differences on your Windows installation however. Note that the Oracle JRE comes bundled with the JDK.
If you ever find that your Java JDK configuration is using the wrong version of the compiler, or it appears to be working by magic, without being explicitly defined so (without casting the spell), then you may have a symlink somewhere in your environment variables. So you may want to check for symlink.

goto Mycomputer(This PC) -> rightclick ->select properties -> Advanced system settings -> environment variables-> in system variables click "New" button and write JAVA_HOME in variable name and path C:\Program Files\Java\jdk1.8.0_131 were jdk is present in variable value-> click ok.
close and reopen the command prompt after setting JAVA_HOME. Sometimes changes does not reflect in the cmd opened before setting the JAVA_HOME.
you can also set JAVA_HOME through terminal itself:
SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"

In Eclipse: Window->Preferences->Java->Installed JREs
Use the search feature to make sure your latest Java installation is listed; then make sure it is the one that is checked. This should be a JDK not a JRE.

While adding your Java directory to your PATH variable, you might want to put it right at the beginning of it. I've had the problem, that putting the Java directory at the end of the PATH would not work. After checking, I've found java.exe in my Windows\System32 directory and it looks like the first one wins, when there are several files with the same name in your PATH...

Run Eclipse as Administrator.
That solved my problem. I'm still digging for the logic behind it.

if you have not restarted your computer after installing jdk just restart your computer.
if you want to make a portable java and set path before using java, just make a batch file i explained below.
if you want to run this batch file when your computer start just put your batch file shortcut in startup folder. In windows 7 startup folder is "C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
make a batch file like this:
set Java_Home=C:\Program Files\Java\jdk1.8.0_11
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin
note:
java_home and path are variables. you can make any variable as you wish.
for example set amir=good_boy and you can see amir by %amir% or you can see java_home by %java_home%

After hours of work around most of the solutions here, the problem was solved for me just by installing 32-bit JDK.

You may wanna look into Windows/System32 folder for the following files:
- java.exe
- javaw.exe
- javaws.exe
Because, the path variable is including these files, you can get a headache trying to figure out why the java -version or javac -version keeps pointing to the old JAVA_HOME: rename those files, take out the extension with an underscore, for instance. And then, you only will have to create the JAVA_HOME variable, add it to the path variable (e.g., %JAVA_HOME%) and append the "\bin" particle. This way you need to only change the JAVA_HOME variable pointing to different JRE or JDK and have multiple installations of java just by setting JAVA_HOME.
This also means that it is better to install Java manually, without an installer, so you are able to toy with it.

Related

the Terminal of Android Studio can't work [duplicate]

I went to the Environment Variables in 'System' in the control panel and made two new variables, one for user variables and one for system variables. Both were named JAVA_HOME and both pointing to
C:\Sun\SDK\jdk\bin
But for some reason, I still get the below error when running a Java command...
BUILD FAILED
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:161: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:141: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:137: Please set java.home to a JDK installation
Total time: 1 second
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish>lib\ant\bin\ant -f setup.xml
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: setup.xml
How can I fix this problem?
Find JDK Installation Directory
First you need to know the installation path for the Java Development Kit.
Open the default installation path for the JDK:
C:\Program Files\Java
There should be a subdirectory like:
C:\Program Files\Java\jdk1.8.0_172
Note: one has only to put the path to the jdk without /bin in the end (as suggested on a lot of places). e.g. C:\Java\jdk1.8.0_172 and NOT C:\Java\jdk1.8.0_172\bin !
Set the JAVA_HOME Variable
Once you have the JDK installation path:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab, then click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
Click Apply Changes.
Note: You might need to restart Windows
The complete article is here, on my blog: Setting JAVA_HOME Variable in Windows.
What worked for me was adding the %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.
You have to first Install JDK in your system.
Set Java Home
JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location of your JDK Installation Directory]
Once you have the JDK installation path:
Right-click the My Computer icon on
Select Properties.
Click the Advanced system setting tab on left side of your screen
Aadvance Popup is open.
Click on Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
Click Apply Changes.
Set JAVA Path under system variable
PATH= C:\Program Files\Java\jdk1.7.0; [Append Value with semi-colon]
In cmd (temporarily for that cmd window):
set JAVA_HOME="C:\\....\java\jdk1.x.y_zz"
echo %JAVA_HOME%
set PATH=%PATH%;%JAVA_HOME%\bin
echo %PATH%
You need to set it to C:\Sun\SDK\jdk (Assuming that is where the JDK is installed - It is not the default) - Do not put the \bin in C:\Sun\SDK\jdk\bin.
If your app only runs when you are logged in as the current user then put it in the user variables - If it needs to run for all users on your system then put it in System variables.
You might also need to add %JAVA_HOME%\bin to the path also (Also it depends on whether you run it from just the user or from all users, including System)
http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html
Control Panel > Java, Java tab, click the View button. In Runtime Parameters, put:
-Djava.home=YOUR_PATH_HERE
Or when you execute Java you can add that command line switch to the command:
java -Djava.home=PATH SomeJavaApp
One Image can fix this issue.
For More
For those who are still stumped with this problem (I tried all the above suggestions) --
If you're on a 64-bit version of Windows and you've installed the 32-bit JDK, besides adjusting PATH variables, you may need to adjust registry variables, too.
I was pulling my hair out, having correctly set my PATH variables -- still to no avail -- and then only finding "vacated" Java entries in my registry, seemingly a deadend of fixing the "misfiring" Java Runtime Environment.
By using Process Monitor to watch the program I was trying to get started, in order to sniff out where it was looking in the registry for Java (Runtime Environment), I triumphantly discovered that it's looking in the 32-bit version of registry entries, found in HKEY_LOCAL_MACHINE\SOFTWARE\**Wow6432Node**\JavaSoft\Java Runtime Environment.
Within that key, you should find subkeys of different Java versions installed (past and/or present). Click on the subkey of the latest version (my subkey is currently 1.7.0_25, for example). After clicking on that subkey, you'll see registry string values listed on the right, and particularly, JavaHome and RuntimeLib. You need to modify the values of those two values to reflect the both the current folder and jvm.dll file, respectively.
For example, in my case, the values were (previously) respectively set at C:\Program Files (x86)\Java\jre7 and C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll which are nonexistent on my machine. I had to update these to the current folder and file of C:\Program Files (x86)\Java\jdk1.7.0_25\jre and C:\Program Files (x86)\Java\jdk1.7.0_25\jre\bin\client\jvm.dll.
Again, this will depend entirely on both what version of Java (JDK and/or JRE) you have installed -- 32 or 64-bit -- and what type of operating system you're on -- 32 or 64-bit. Just know that they're reflected in different locations within the registry (like the Wow6432Node for 32 bit applications, in my case with the 32-bit JDK installed on a 64-bit machine).
Now that I've updated those two registry values, my program runs flawlessly, with no more hiccups or complaints about a missing Java Runtime Environment (stemming from the registry).
This is the official solution for setting the Java environment from www.java.com - here.
There are solutions for Windows 7, Windows Vista, Windows XP, Linux/Solaris and other shells.
Example
Windows 7
Select Computer from the Start menu
Choose System Properties from the context menu
Click Advanced system settings -> Advanced tab
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Reopen Command prompt window, and run your Java code.
Windows 7
Go to Control Panel\All Control Panel Items\User Accounts using Explorer (not Internet Explorer!)
or
click on the Start button
click on your picture
Change my environment variables
New...
(if you don't have enough permissions to add it in the System variables section, add it to the User variables section)
Add JAVA_HOME as Variable name and the JDK location as Variable value > OK
Test:
open a new console (cmd)
type set JAVA_HOME
expected output: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
We need to make a distinction between the two environment variables that are discussed here interchangeably. One is the JAVA_HOME variable. The other is the Path variable. Any process that references the JAVA_HOME variable is looking for the search path to the JDK, not the JRE. The use of JAVA_HOME variable is not meant for the Java compiler itself. The compiler is aware of its own location. The variable is meant for other software to more easily locate the compiler. This variable is typically used by IDE software in order to compile and build applications from Java source code. By contrast, the Windows CMD interpreter, and many other first and third party software references the Path variable, not the JAVA_HOME variable.
Use case 1: Compiling from CMD
So for instance, if you are not using any IDE software, and you just want to be able to compile from the CMD, independent of your current working directory, then what you want is to set the Path variable correctly. In your case, you don't even need the JAVA_HOME variable. Because CMD is using Path, not JAVA_HOME to locate the Java compiler.
Use case 2: Compiling from IDE
However, if you are using some IDE software, then you have to look at the documentation first of all. It may require JAVA_HOME to be set, but it may also use another variable name for the same purpose. The de-facto standard over the years has been JAVA_HOME, but this may not always be the case.
Use case 3: Compiling from IDE and CMD
If in addition to the IDE software you also want to be able to compile from the CMD, independent of your current working directory, then in addition to the JAVA_HOME variable you may also need to append the JDK search path to the Path variable.
JAVA_HOME vs. Path
If your problem relates to compiling Java, then you want to check the JAVA_HOME variable, and Path (where applicable). If your problem relates to running Java applications, then you want to check your Path variable.
Path variable is used universally across all operating systems. Because it is defined by the system, and because it's the default variable that's used for locating the JRE, there is almost never any problem running Java applications. Especially not on Windows where the software installers usually set everything up for you. But if you are installing manually, the safest thing to do is perhaps to skip the JAVA_HOME variable altogether and just use the Path variable for everything, for both JDK and the JRE. Any recent version of an IDE software should be able to pick that up and use it.
Symlinks
Symbolic links may provide yet another way to reference the JDK search path by piggybacking one of the existing environment variables.
I am not sure about previous versions of Oracle/Sun JDK/JRE releases, but at least the installer for jdk1.8.0_74 appends the search path C:\ProgramData\Oracle\Java\javapath to the Path variable, and it puts it at the beginning of the string value. This directory contains symbolic links to the java.exe, javaw.exe and javaws.exe in the JRE directory.
So at least with the Java 8 JDK, and presumably the Java 8 JRE standalone, no environment variable configuration needs to be done for the JRE. As long as you use the installer package to set it up. There may be differences on your Windows installation however. Note that the Oracle JRE comes bundled with the JDK.
If you ever find that your Java JDK configuration is using the wrong version of the compiler, or it appears to be working by magic, without being explicitly defined so (without casting the spell), then you may have a symlink somewhere in your environment variables. So you may want to check for symlink.
goto Mycomputer(This PC) -> rightclick ->select properties -> Advanced system settings -> environment variables-> in system variables click "New" button and write JAVA_HOME in variable name and path C:\Program Files\Java\jdk1.8.0_131 were jdk is present in variable value-> click ok.
close and reopen the command prompt after setting JAVA_HOME. Sometimes changes does not reflect in the cmd opened before setting the JAVA_HOME.
you can also set JAVA_HOME through terminal itself:
SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"
In Eclipse: Window->Preferences->Java->Installed JREs
Use the search feature to make sure your latest Java installation is listed; then make sure it is the one that is checked. This should be a JDK not a JRE.
While adding your Java directory to your PATH variable, you might want to put it right at the beginning of it. I've had the problem, that putting the Java directory at the end of the PATH would not work. After checking, I've found java.exe in my Windows\System32 directory and it looks like the first one wins, when there are several files with the same name in your PATH...
Run Eclipse as Administrator.
That solved my problem. I'm still digging for the logic behind it.
if you have not restarted your computer after installing jdk just restart your computer.
if you want to make a portable java and set path before using java, just make a batch file i explained below.
if you want to run this batch file when your computer start just put your batch file shortcut in startup folder. In windows 7 startup folder is "C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
make a batch file like this:
set Java_Home=C:\Program Files\Java\jdk1.8.0_11
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin
note:
java_home and path are variables. you can make any variable as you wish.
for example set amir=good_boy and you can see amir by %amir% or you can see java_home by %java_home%
After hours of work around most of the solutions here, the problem was solved for me just by installing 32-bit JDK.
You may wanna look into Windows/System32 folder for the following files:
- java.exe
- javaw.exe
- javaws.exe
Because, the path variable is including these files, you can get a headache trying to figure out why the java -version or javac -version keeps pointing to the old JAVA_HOME: rename those files, take out the extension with an underscore, for instance. And then, you only will have to create the JAVA_HOME variable, add it to the path variable (e.g., %JAVA_HOME%) and append the "\bin" particle. This way you need to only change the JAVA_HOME variable pointing to different JRE or JDK and have multiple installations of java just by setting JAVA_HOME.
This also means that it is better to install Java manually, without an installer, so you are able to toy with it.

JAVA_HOME not visiable in system variables [duplicate]

I went to the Environment Variables in 'System' in the control panel and made two new variables, one for user variables and one for system variables. Both were named JAVA_HOME and both pointing to
C:\Sun\SDK\jdk\bin
But for some reason, I still get the below error when running a Java command...
BUILD FAILED
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:161: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:141: The following error occurred while executing this line:
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish\setup.xml:137: Please set java.home to a JDK installation
Total time: 1 second
C:\Users\Derek\Desktop\eclipse\eclipse\glassfish>lib\ant\bin\ant -f setup.xml
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: setup.xml
How can I fix this problem?
Find JDK Installation Directory
First you need to know the installation path for the Java Development Kit.
Open the default installation path for the JDK:
C:\Program Files\Java
There should be a subdirectory like:
C:\Program Files\Java\jdk1.8.0_172
Note: one has only to put the path to the jdk without /bin in the end (as suggested on a lot of places). e.g. C:\Java\jdk1.8.0_172 and NOT C:\Java\jdk1.8.0_172\bin !
Set the JAVA_HOME Variable
Once you have the JDK installation path:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab, then click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
Click Apply Changes.
Note: You might need to restart Windows
The complete article is here, on my blog: Setting JAVA_HOME Variable in Windows.
What worked for me was adding the %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.
You have to first Install JDK in your system.
Set Java Home
JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location of your JDK Installation Directory]
Once you have the JDK installation path:
Right-click the My Computer icon on
Select Properties.
Click the Advanced system setting tab on left side of your screen
Aadvance Popup is open.
Click on Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
Click Apply Changes.
Set JAVA Path under system variable
PATH= C:\Program Files\Java\jdk1.7.0; [Append Value with semi-colon]
In cmd (temporarily for that cmd window):
set JAVA_HOME="C:\\....\java\jdk1.x.y_zz"
echo %JAVA_HOME%
set PATH=%PATH%;%JAVA_HOME%\bin
echo %PATH%
You need to set it to C:\Sun\SDK\jdk (Assuming that is where the JDK is installed - It is not the default) - Do not put the \bin in C:\Sun\SDK\jdk\bin.
If your app only runs when you are logged in as the current user then put it in the user variables - If it needs to run for all users on your system then put it in System variables.
You might also need to add %JAVA_HOME%\bin to the path also (Also it depends on whether you run it from just the user or from all users, including System)
http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html
Control Panel > Java, Java tab, click the View button. In Runtime Parameters, put:
-Djava.home=YOUR_PATH_HERE
Or when you execute Java you can add that command line switch to the command:
java -Djava.home=PATH SomeJavaApp
One Image can fix this issue.
For More
For those who are still stumped with this problem (I tried all the above suggestions) --
If you're on a 64-bit version of Windows and you've installed the 32-bit JDK, besides adjusting PATH variables, you may need to adjust registry variables, too.
I was pulling my hair out, having correctly set my PATH variables -- still to no avail -- and then only finding "vacated" Java entries in my registry, seemingly a deadend of fixing the "misfiring" Java Runtime Environment.
By using Process Monitor to watch the program I was trying to get started, in order to sniff out where it was looking in the registry for Java (Runtime Environment), I triumphantly discovered that it's looking in the 32-bit version of registry entries, found in HKEY_LOCAL_MACHINE\SOFTWARE\**Wow6432Node**\JavaSoft\Java Runtime Environment.
Within that key, you should find subkeys of different Java versions installed (past and/or present). Click on the subkey of the latest version (my subkey is currently 1.7.0_25, for example). After clicking on that subkey, you'll see registry string values listed on the right, and particularly, JavaHome and RuntimeLib. You need to modify the values of those two values to reflect the both the current folder and jvm.dll file, respectively.
For example, in my case, the values were (previously) respectively set at C:\Program Files (x86)\Java\jre7 and C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll which are nonexistent on my machine. I had to update these to the current folder and file of C:\Program Files (x86)\Java\jdk1.7.0_25\jre and C:\Program Files (x86)\Java\jdk1.7.0_25\jre\bin\client\jvm.dll.
Again, this will depend entirely on both what version of Java (JDK and/or JRE) you have installed -- 32 or 64-bit -- and what type of operating system you're on -- 32 or 64-bit. Just know that they're reflected in different locations within the registry (like the Wow6432Node for 32 bit applications, in my case with the 32-bit JDK installed on a 64-bit machine).
Now that I've updated those two registry values, my program runs flawlessly, with no more hiccups or complaints about a missing Java Runtime Environment (stemming from the registry).
This is the official solution for setting the Java environment from www.java.com - here.
There are solutions for Windows 7, Windows Vista, Windows XP, Linux/Solaris and other shells.
Example
Windows 7
Select Computer from the Start menu
Choose System Properties from the context menu
Click Advanced system settings -> Advanced tab
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Reopen Command prompt window, and run your Java code.
Windows 7
Go to Control Panel\All Control Panel Items\User Accounts using Explorer (not Internet Explorer!)
or
click on the Start button
click on your picture
Change my environment variables
New...
(if you don't have enough permissions to add it in the System variables section, add it to the User variables section)
Add JAVA_HOME as Variable name and the JDK location as Variable value > OK
Test:
open a new console (cmd)
type set JAVA_HOME
expected output: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
We need to make a distinction between the two environment variables that are discussed here interchangeably. One is the JAVA_HOME variable. The other is the Path variable. Any process that references the JAVA_HOME variable is looking for the search path to the JDK, not the JRE. The use of JAVA_HOME variable is not meant for the Java compiler itself. The compiler is aware of its own location. The variable is meant for other software to more easily locate the compiler. This variable is typically used by IDE software in order to compile and build applications from Java source code. By contrast, the Windows CMD interpreter, and many other first and third party software references the Path variable, not the JAVA_HOME variable.
Use case 1: Compiling from CMD
So for instance, if you are not using any IDE software, and you just want to be able to compile from the CMD, independent of your current working directory, then what you want is to set the Path variable correctly. In your case, you don't even need the JAVA_HOME variable. Because CMD is using Path, not JAVA_HOME to locate the Java compiler.
Use case 2: Compiling from IDE
However, if you are using some IDE software, then you have to look at the documentation first of all. It may require JAVA_HOME to be set, but it may also use another variable name for the same purpose. The de-facto standard over the years has been JAVA_HOME, but this may not always be the case.
Use case 3: Compiling from IDE and CMD
If in addition to the IDE software you also want to be able to compile from the CMD, independent of your current working directory, then in addition to the JAVA_HOME variable you may also need to append the JDK search path to the Path variable.
JAVA_HOME vs. Path
If your problem relates to compiling Java, then you want to check the JAVA_HOME variable, and Path (where applicable). If your problem relates to running Java applications, then you want to check your Path variable.
Path variable is used universally across all operating systems. Because it is defined by the system, and because it's the default variable that's used for locating the JRE, there is almost never any problem running Java applications. Especially not on Windows where the software installers usually set everything up for you. But if you are installing manually, the safest thing to do is perhaps to skip the JAVA_HOME variable altogether and just use the Path variable for everything, for both JDK and the JRE. Any recent version of an IDE software should be able to pick that up and use it.
Symlinks
Symbolic links may provide yet another way to reference the JDK search path by piggybacking one of the existing environment variables.
I am not sure about previous versions of Oracle/Sun JDK/JRE releases, but at least the installer for jdk1.8.0_74 appends the search path C:\ProgramData\Oracle\Java\javapath to the Path variable, and it puts it at the beginning of the string value. This directory contains symbolic links to the java.exe, javaw.exe and javaws.exe in the JRE directory.
So at least with the Java 8 JDK, and presumably the Java 8 JRE standalone, no environment variable configuration needs to be done for the JRE. As long as you use the installer package to set it up. There may be differences on your Windows installation however. Note that the Oracle JRE comes bundled with the JDK.
If you ever find that your Java JDK configuration is using the wrong version of the compiler, or it appears to be working by magic, without being explicitly defined so (without casting the spell), then you may have a symlink somewhere in your environment variables. So you may want to check for symlink.
goto Mycomputer(This PC) -> rightclick ->select properties -> Advanced system settings -> environment variables-> in system variables click "New" button and write JAVA_HOME in variable name and path C:\Program Files\Java\jdk1.8.0_131 were jdk is present in variable value-> click ok.
close and reopen the command prompt after setting JAVA_HOME. Sometimes changes does not reflect in the cmd opened before setting the JAVA_HOME.
you can also set JAVA_HOME through terminal itself:
SET JAVA_HOME="C:\Program Files (x86)\Java\jdk1.8.0_131"
In Eclipse: Window->Preferences->Java->Installed JREs
Use the search feature to make sure your latest Java installation is listed; then make sure it is the one that is checked. This should be a JDK not a JRE.
While adding your Java directory to your PATH variable, you might want to put it right at the beginning of it. I've had the problem, that putting the Java directory at the end of the PATH would not work. After checking, I've found java.exe in my Windows\System32 directory and it looks like the first one wins, when there are several files with the same name in your PATH...
Run Eclipse as Administrator.
That solved my problem. I'm still digging for the logic behind it.
if you have not restarted your computer after installing jdk just restart your computer.
if you want to make a portable java and set path before using java, just make a batch file i explained below.
if you want to run this batch file when your computer start just put your batch file shortcut in startup folder. In windows 7 startup folder is "C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
make a batch file like this:
set Java_Home=C:\Program Files\Java\jdk1.8.0_11
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin
note:
java_home and path are variables. you can make any variable as you wish.
for example set amir=good_boy and you can see amir by %amir% or you can see java_home by %java_home%
After hours of work around most of the solutions here, the problem was solved for me just by installing 32-bit JDK.
You may wanna look into Windows/System32 folder for the following files:
- java.exe
- javaw.exe
- javaws.exe
Because, the path variable is including these files, you can get a headache trying to figure out why the java -version or javac -version keeps pointing to the old JAVA_HOME: rename those files, take out the extension with an underscore, for instance. And then, you only will have to create the JAVA_HOME variable, add it to the path variable (e.g., %JAVA_HOME%) and append the "\bin" particle. This way you need to only change the JAVA_HOME variable pointing to different JRE or JDK and have multiple installations of java just by setting JAVA_HOME.
This also means that it is better to install Java manually, without an installer, so you are able to toy with it.

Unable to set current Java version to earlier version

I have both Java 8 and 7 installed. I set the JAVA_HOME variable to the path to the java 7 jdk bin folder, and it is included in PATH. I double checked everything.
However, when I type Java -version, I get Java 8.
I am using Windows 7.
Add JAVA_HOME\bin to the beginning of your path. If you´re on windows:
set PATH=%JAVA_HOME%\bin;%PATH%
or
set PATH=C:\Program Files\Java\jdk1.7.0_79\bin;%PATH%
Your OS will pick the java which appear first in the system environment variable called PATH. So set the Java7 home first in the path variable like this
set PATH=%JAVA_HOME%\bin;%PATH%
This is applicable for the terminal you have opened.
If you want to set this permanently follow the instructions
Right-click the My Computer icon on.
your desktop and select Properties.
Click the Advanced tab. Click the.
Environment Variables button. ...
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Click OK.
I found the solution. I moved JAVA_HOME variable earlier in the PATH and it works now.
When typing a command on your shell (both windows and linux), the executable is searched in folders specified in your PATH from left to right, i.e. if PATH=folder1;folder2;folder3, your shell will search for the command in the folder1, then in folder2, and finally in folder3.
I suppose your PATH looks like PATH=jdk8_bin_folder;windows_stuff;jdk7_bin_folder;other_stuff. So, when typing java, your shell will find the jdk8 before the jdk7.
A common solution is (as already says) to use the JAVA_HOME variable to store the jdk folder, and use it in your PATH :)
You have to do two things
Remove Java.exe, javaw.exe and javac.exe from system32folder
if C:\ProgramData\Oracle\Java\javapath exists in path of the system environment variable then remove. when installing new version of java, installer set it automatically
Now set JAVA_HOME and set path(%JAVA_HOME%\bin)

Can't open Android studio. (issues related to JDK)

As mentioned in Question Title, I am unable to open Android Studio.
When I am trying to open it, below message is shown:
"The environment variable JAVA_HOME (with the value of
C:\Program Files\Java\jdk.1.8.0_31\bin;) does not point
to a valid JVM installation."
How can I solve this problem?
Try removing \bin from the end of your JAVA_HOME system variable.
Your path variable for Java Installation is probably corrupt maybe due to a re-install or you didn't set it in the first place.
This can be easily fixed.
First install the latest version of JAVA SE from this webpage.
To set the temporary path of JDK (in windows), you need to follow following steps:
Open command prompt
copy the path of jdk/bin directory under program files. note it's "jdk" not "jre".
write in command prompt: set path=*copied_path*
For Example:
set path=C:\Program Files\Java\jdkx.x.x_23\bin
where x.x.x are the jdk version related number
It is useful to set the PATH environment variable permanently so it will persist after rebooting. You can read more about how to do this over here: Set PATH and CLASSPATH

How to set path for Jre 6 when jre 7 installed?

I am programming through java 1.6 u_17, but i have JRE version 6 and JRE version 7 installed, so how to run my compiled program from JDK 1.6 to run through the JRE 6 only?
By Default, it runs my class files through JRE 7, how to change this behavior? Any idea of setting Class path in windows 7, as we does it for JDK.
The following is shown in my command prompt
E:\JAVA>javac -version
javac 1.6.0_17
E:\JAVA>java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)
This is for my SET command showing the Windows 7 environment paths
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
ClassPath=C:\Program Files\Java\jdk1.6.0_17\bin\mysql-connector-java-5.1.5-bin.jar;
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=RANDMATE-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Administrator
JAVA_HOME=C:\Program Files\Java\jre6\bin;
LOCALAPPDATA=C:\Users\Administrator\AppData\Local
LOGONSERVER=\\RANDMATE-PC
NUMBER_OF_PROCESSORS=2
OS=Windows_NT Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_17\bin;C:\Program Files\Java\jre6\bin;C:\Program Files\MyS
QL\MySQL Server 5.1\bin;C:\Program Files\UltraEdit\;C:\Program Files\Jar2Exe Wizard\;C:\Program Files\Java\jre6\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 6 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0605
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\ADMINI~1\AppData\Local\Temp
TMP=C:\Users\ADMINI~1\AppData\Local\Temp
USERDOMAIN=RANDMATE-PC
USERNAME=Administrator
USERPROFILE=C:\Users\Administrator
windir=C:\Windows
Looks like you are using Windows. Please go the Environment Variables and define a user variable as:
Right Click(My Computers) -> Advanced -> Environment Variables -> Add
Variable Name = JAVA_HOME
Variable Value = Root Folder of Java 1.6.0_17 installation
Also in the same screen, please check the PATH variable and make sure **bin** Folder of Java 1.6.0_17 installation is added in the path preferably in the beginning and remove the Java 7 from the path, if it is there.
I fix this problem by removing the java.exe in system32 folder. And then in the cmd the java command refer to the jdk set in the path enviroment variable.
java.exe is also available in C:\windows\system32 and in your case its version might be 1.7..
Since your path has C:\windows\system32 first. no matter how to set rest of the path, sonar always will load jre7. (refer to conf\wrapper.conf in Sonar directory, by default it has wrapper.java.command=java)
To fix this, change following property of the "wrapper.conf" file
wrapper.java.command=C:\Program Files\Java\jdk1.6.0_XX\bin\java
this will fix the issue irrespective of the path variables.
For those who had the same problem I suggest reading this thread:
https://superuser.com/questions/479889/wrong-java-version-being-reported
Quote of wmz: "To check what actually executes when you run 'java -version' run from command line:
for %I in (java.exe) do #echo %~$PATH:I"
Windows is checking the PATH variable to find an executable named java and using that to launch your application. It is quite normal in a development environment to have many installations (as you do). However this calls on you to manage your environment.
There are two ways for you to set environment variables in Windows. By going to My Computer > Advanced Settings > Environment Variables as described above, you can set a variabler to your JDK installation and then update the Path to find the bin directory in that installation. Youy have the choice of updating System variables (all users) or user variables (your account only).
Personally, I prefer not to use the system/user environment variables as this provides less flexibility. You can use bat files to explicitly set the Path for a specific moment in time, or indeed to override the JAVA_HOME to point to a different installation.
If you are using an IDE you can usually specify the target runtime on a per project basis. Alternatively, when running the program, provide the fully qualified path to the version of the java executable you wish to use.
I had same problem. Issue is that Java installation will copy a java.exe, javaw.exe and javaws.exe to windows/system32 directory. You must have installed JDK7 recently.
I just removed those files from Windows/System32 directory, however, kept older version in path. This solved the issue.
Try it out.
I was facing the similar problem. I am using Java 7 and Java 8 together. The Java 8 was installed in the machine but the 7 set-up I copied from another system. I have already set the JAVA_HOME & path pointing to 7. But when I try to echo %path%, it shows the Jdk 8 in the class path. after lots of google, I have found "C:\ProgramData\Oracle\Java\javapath" in the path. Removing the line from the path solved the problem.
Background
I'm using Windows 8.1 and I have both JDK6 and JDK8 installed. For development purpose, I needed to get java version "1.6.0_45" over the command java -version and javac 1.6.0_45 over javac -version. The second command was working as expected after setting JAVA_HOME as Home folder of JDK6 and adding %JAVA_HOME/bin% in Path. However the first command was still returning java version "1.8.0_71"
Troubleshooting
I could find the an entry in the Path environment variable which points to C:\ProgramData\Oracle\Java. This folder actually contains short cut to java.exe of JDK8.
Proper solution: Uninstall JDK 8
Workaround:Edit the short cut file so that it points towards java.exe inside %JAVA_HOME%\bin (Please replace the variable with actual folder)
set the PATH variable to your jdk6\bin directory. so that it will pick the javac and java from jdk6.
for setting the path variable go to Environment Variables.
After setting the path variables you need to restart your command prompt. (NOT the computer).
Just right click on MyComputer, then Advanced System Settings-->Environment Variables-->New
Then in the "variable Name" text field add the string "PATH" or if it already exists select PATH from the list and click edit then append the path for "bin" folder in java in program files to the Variable value text field followed by a semicolon (;), if not exits add the path of bin directory of your java folder in "Variable Value" field and click "OK".
If you want to check the result, open up a command prompt and type "java" then hit enter.
For windows 7(X86) path setting:
first step:
Mycomputer(Right click)-->properties-->advanced settings-->environment variales-->new
(user variable)
on this first varible name: "" JAVA_HOME "" value: "" C:\Program Files\Java\jdk1.7.0_45 ""
second variable name: "" PATH "" value: "" C:\Program Files\Java\jdk1.7.0_45\bin;.; ""
There are two types of path for java : Permanent & Temporary.
Here is the video tutorial describing how to set path for Java?
How to Set path for Java : https://www.youtube.com/watch?v=rM4Qq3Ua7Sk
This video tutorial will guide you in setting permanent and temporary path for Java. Simply follow the steps. This will work with any version of Java, JDK or JRE. In video I have used path of JDK, Simply copy path of JRE instead of JDK and rest is same.
OR read the tutorial here : How to Set path for Java : http://aatul.me/2011/08/24/how-to-set-path-for-java/
Hope this solutions will help you.

Categories