JDK 32bit and 64bit on JAVA_HOME simultaneously - java

I am using smartGIT in Windows 8.1 which uses 32Bit JDK (1.8), I needed to set JAVA_HOME to 32bit directory
but now Im using as well Android Studio which needs JDK 64bit (1.8 installed), and I need to set JAVA_HOME pointing to 64bit directory
is there a way to set them both on the same variable and depending if the software requires either JDK 32 or 64 can pick the appropriate framework???
I tried to set them simultaneously by separate them with a semi colon like this
JAVA_HOME
C:\Program Files\Java\jdk1.8.0_25\;C:\Program Files (x86)\Java\jdk1.8.0_25
but this just works with 32BIT version, 64BIT is still doesn't work
thanks for the support

This is not a direct answer to your question. But I think this will help you to solve the underline problem of running SmartGit on 64bit JVM.
Go to bin folder under SmartGit installation directory. There you can find the "smartgit64.exe" executable to launch SmartGit in 64bit mode.
I have it running smoothly in Win8.1 64bit with 64bit JDK.

There is no way to have a static JAVA_HOME that satisfies version or bitness specific subprocess that I know of.
You don't say what platform you are on, but generally environment variables exported such that subprocesses can use them are fixed, are used as a basis for further tweaks, or are completely redefined.
But, what you can do is try to tweak the environment that those processes are called from so they have their own custom environment. For example, you could have your own JAVA_ROOT set, andf then use that as a basis for creating JAVA_HOME along with a hard-coded or script/function fetched environment variable for a specific JRE to make the "real" JAVA_HOME for everything run from this subshell.
Alternatively, if you are on OS X, there is a utility that can be used to set and fetch system information for installed JREs. This can be used in scripts, etc. Other platforms have similar tools.
Also, look hard at your toolset. Make sure that JAVA_HOME is the only way to set the VM it uses -- often this is just one of the ways you can set this.
[EDIT]
I forgot about the -d32 trick mentioned in the comments. That would be nice solution if it works, and you can use the same versions of the VM for all invocations.
[EDIT]
Ok, since you are on Windows, you could try launching each Java app from its own environment. A .cmd or .bat file if that is the way you roll, or you could create a Windows shortcut that you tweak before invoking the specific app.
For example, if one has a Java main they want to run from the command line, it is easy to wrap the entire command line in a .bat file. e.g.:
set JAVA_HOME=C:\Some\Path\To\A\JRE
set APP_HOME=C:\Some\Path\To\A\Jar
set JAVA_OPTS="-Dfoo=bar"
%JAVA_HOME%\bin\java.exe %JAVA_OPTS% -jar %APP_HOME%\myApp.jar
Now, running this jarfile will use the specific Java executable you set, and also pass the new JAVA_HOME environment to the Java process that it starts. This overwrites any "default" JAVA_HOME you have set in your User or System environment.
Any other processes will not see this JAVA_HOME, and when the .bat file exits the new definition disappears.
Alternatively, if you always start your Java apps or Java tools by double-clicking them, you might be able to wrap those applications in a Windows shortcut -- even if you just prepend the executable with "set JAVA_HOME=..." I always forget how tweaky this is, though, so I'm hand-waving a bit!

Related

can't install R package due to java error [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.

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.

How important is setting environment variables in Java?

I am writing a blog where I have explain my students how to install Java, but I'm wondering why should expose them to this complicated part of Java installation. When I used Java before, I used right out of the box with my IDE. But all the tutorials I see mention configuration of these environment variables.
Maybe my PATH variables were set from previous installations, however I don't remember doing it.
Can anyone please advise if environment variable setting can be left to the IDEs or has to be done manually?
Java does not need any environment variables to be set.
However, setting some environment variables makes some things easier.
PATH If the jre/bin folder is on the path, you don't have to qualify to run the java command. If the jdk/bin folder is on the path, you don't have to qualify to run the java and javac commands. As well as some other commands provided by Java.
JAVA_HOME Used by many Java programs and installers to find Java.
When using an IDE, it can usually find / prompt for Java installations, so it doesn't need any environment variables. The IDE won't set them either.
As mentioned above, JAVA_HOME Used by many Java programs and installers to locate Java. for instance, Tomcat requires the environment variable JAVA_HOME to be set to the JDK installed directory.
To check if JAVA_HOME is already set, start a terminal and issue:
echo $JAVA_HOME
JAVA_HOME is to be set to the JDK installed directory. You need to find your JDK installed directory.
[TODO] find macOS and Ubuntu JDK installed directory.
Add the the following line at the end of "~/.bashrc" (or "~/.login"). Take note that filename beginning with dot (.) is hidden by default.
[TODO] How to un-hide for macOS/Ubuntu.
export JAVA_HOME=/path/to/JDK-installed-directory
// Verify the new setting
echo $JAVA_HOME
I installed Java and then installed Eclipse, and you know what, it worked fine, however for one of my colleagues it was giving a "warning" regarding not being able to find Java, and error was clearly showing it needs environment variables because it wasn't able to find the path to Java, like Java wasn't installed, while it was installed there.

Make jar run in 32bit jre

How can I specify that in order to run a certain java application that I created you need to have 32 bit JRE installed on your system? Further how can I specify that the java application is to use the 32 bit JRE and not the 64 bit JRE if they are both installed?
Background:
I have created an application that uses a 3rd party 32 bit only library. The application can not run in a 64 bit JRE.
I am going to be distributing this application to a lot of computers in my company, so I need to be able to in code or in the export process, specify the required JRE.
I am using eclipse, Kepler to develop and build the java application.
The idea of java is always compile once and run everywhere, regardless of OS, cpu architecture etc, so you might be heading the wrong direction here.
But nevertheless here are some system properties you might / not find helpful. I've listed the property key and value I have when I check it (I run Oracle JDK on Win7 64)
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
sun.arch.data.model: 64
sun.cpu.isalist: amd64
To use any of those just do
String vmname = System.getProperty("java.vm.name");
You can't do it directly in Java, since you're in a running JVM at that point. My solution was to write a dos batch script to set the JAVA_HOME and add %JAVA_HOME%\bin at the front of the PATH. For example, I have sethome.bat which contains
#echo off
set "JAVA_HOME=c:\Program Files (x86)\Java\jre6"
set "PATH=%JAVA_HOME%\bin;%PATH%"
Then I use
call "%SERVICE_HOME%\sethome"
"%JAVA_HOME%\bin\java" -version
echo If this does not look correct press CTRL-C to cancel otherwise
pause
You cannot generally make sure what program runs your jar. I can pass the jar to acroread, or zip or whatever, and you can't do anything about it.
So, I'd just try to load the library, and do a proper error/exception handling. Who knows? Maybe your client has meanwhile replaced that library with a 64bit version, without you knowing about it? SO, this: loading, and if it won't aborting with a graceful eror message is the only sensible thing.

Switch between 32-bit and 64-bit JDK platform on Windows 7

I am using Windows 7 on my laptop. I am working with jpcap libraries which work only on 32-bit JDK. Having both 32 and 64 bit JDKs installed on my machine. How can I switch between 64-bit and 32-bit JDK?
I tried changing the %JAVAHOME% and %PATH% environment variables, but it didn't work. Should I change anything in the registry?
#Srikant Sahay, Thank you very much! It did work on widnows 8.1 64 bit OS.
I am able to Switch between 32-bit and 64-bit JDK platform on Windows 8.1 on demand. The trick, as Srikant suggested, is to set the path before all other path variables. Make sure you put fist in the path variable.
java -d32 -version ( or simply )
java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)
However, only one instance works at a time. Either you choose the 32 bit version or the 64 bit version. So, if you type "java -d64 -version" you will get
Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.
Therefore, if you instead want a 64bit JVM you should put the JDk installation folder(in my case "C:\Program Files\Java\jdk1.7.0_51\bin" since the OS is 64 bit by default) first in the path variable.
cheers!
You can either set your path, or switch between JDK's in your IDE. Personally I use JetBrains IntelliJ IDEA and set the JDK via the IDE.
Setting via IDE:
From within a project:
click File -> Project Structure
Select Project under Project Settings
Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK
From a new project:
Click File -> New Project
Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK
If you want to set your path:
Follow the directions listed on the java.com site.
Keep in mind that your jar will run using whatever version of java is specified in your PATH.
If your PATH variable is not working, try cleaning up your path variable by removing unnecessary entries and rebooting. After reboot add Java to the path and reboot again.
If your still having issues, try executing using the absolute path of the java version your trying to use to ensure it works. If it does work, check your path variable against it to ensure it is accurate.
No, don't touch the registry. Each running Java application gets a single unique JVM instance. So a single java program cannot run some parts of the code in one JVM and other parts of the code in another JVM, as far as I know. You can, however, choose which JRE a particular java program runs in, so you can run the entire jpcap program in your 32 bit java version. Use a startup script (batch file) that points to the exact location of java.exe. When you run "java MyClassName" it's really just finding the java executable on the PATH environment variable, so by explicitly specifying your path, you get to choose your version. In other words, if you run a java program using "java MyClassName" (or if a program on your machine does so) it will use the java.exe application found on your PATH environment variable. Applications themselves can use whatever environment variables they choose: typically the ones used for java are JAVA_HOME and JRE_HOME. So you might want to try setting both of those and then trying to run your program again.
Set the path of your java in System Environment Variables PATH variable. Set it to be before any other path (even System 32 if java or javaw is present there).

Categories