setting issue of JAVA_HOME and JAVA_PATH - java

I have been using Eclipse to develop java program on a windows 7 machine. It works. I also typed "java" from the command prompt, it also shows the help message. In other words, I think Java was correctly installed on this machine. However, when I open the "environmental variable" setting on this machine, I cannot find either "JAVA_HOME" setting and "JAVA PATH" setting. What is the problem of this?

Java also copies java.exe and javaw.exe under C:\Windows\System32, there's where your java is running from.
You can confirm that by using where commmand:
On my win7 machine:
>where java.exe
C:\Windows\System32\java.exe

Some environment variables are defined at machine level and some are defined (and overwritten) at user account level. Just do following in windows cmd prompt:
c:\echo %PATH% or just type c:\path
and verify the output.
You can also verify java home path by writing a simple Test class like following:
public class Test {
public static void main(String[]s){
System.out.println(System.getProperty("java.home"));
}
}

There are multitudes of links to be fond on Google regarding how to solve this in Windows. These environment variables typically do not get setup by default when installing java.
Here are some 10 second finds with with answers:
How to set java_home on Windows 7?
Setting the JAVA_HOME Variable in Windows
Installing Java on Windows 7 and setting-up the JAVA_HOME

Check you PATH variable in Environment Variables. It must be set to jreInstallation/bin. Windows does not pick up java command from JAVA PATH, it picks java command from PATH variable.
Also note that once you install JDK, path is not set by installation to jdkInstallation/bin, you need to set it up explicitly.So unless you set the path to jdkInstallation/bin, javac wont be recognized.

Check your path variable in windows environmental variables. At least Java path should be there .
It may looks like this.
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0\bin

You should set path and classpath variables.
Here's the link you can follow for step by step instructions.
[http://abodeqa.wordpress.com/2012/08/11/how-to-set-path/][1]

With Java, Groovy, Git, Heroku, Maven, and many other projects, what I always do is this:
1. Unzip the software package into a directory, for example:
C:\AeroFS\Java\jdk1.7.0_25
C:\AeroFS\Groovy\groovy-2.0.5
2. Create a HOME variable, such as JAVA_HOME or GROOVY_HOME that points to the
above locations.
3. Put these in your default system path by editing your PATH variable and
adding %JAVA_HOME%\bin and %GROOVY_HOME%\bin to the end of your PATH. In
the case of JAVA_HOME only, you might want to put it at the beginning of
the PATH to override the java.exe that rests in the WINDOWS directory
location.

Related

JDK installed but no javap?

I have the JDK 10.0.2 installed, have the cmd opened in the folder of the class files of my program and try the command: javap Simulation.class .
I get the error that the command javap is not found. What do I do wrong?
You must have your $JAVA_HOME/bin directory added to system PATH for javap command to be available without it's absolute path.
Alternatively you can call javap using the absolute path:
/usr/lib/.../bin/javap Simulation.class
Assuming you are on Windows, check in your environment variable PATH whether path to Java executables is set.
Ex. If you have installed Java on path,say, C:\Program Files\Java\jdk-10
Then you have to add C:\Program Files\Java\jdk-10\bin to your PATH environment variable to be able to execute java commands from anywhere on command line.
References for Oracle Docs
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm#JSJIG-GUID-DAF345BA-B3E7-4CF2-B87A-B6662D691840
https://www.java.com/en/download/help/path.xml
On a sidenote, recommend you to move to Java 11 or 17 now that Java 10 is no longer supported. The above instructions would still remain same.
append $JAVA_HOME/bin to system $PATH variable. for example on linux
JAVA_HOME= "path of java installation on system"
export PATH = $JAVA_HOME/bin:$PATH
Open the control panel and type envir in search bar.
Click on edit the system environment variables.
Click on environment variables in the advanced system properties.
Click on path mentioned in user variables.
Edit the path, and click new and paste the path of java jdk.
In my system, the path is C:\Program Files\Java\jdk-17.0.2\bin, it could be different for your system.
Click ok, the problem must be solved now.

"The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe"

I am on JDK 8u25 on Windows 8, and I am experiencing a problem with my Java installation. I can run javac perfectly fine, but running java produces this error message:
The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
How do I fix this?
I think the problem has to do with my environment variables.
The important variables, as I have set them, are:
JAVA_HOME – C:\Program Files\Java\jdk1.8.0_25
CLASSPATH – .;%JAVA_HOME%\lib
PATH – <other paths omitted>;%JAVA_HOME%\bin
And their expansions, as viewed with set in cmd, are:
JAVA_HOME – C:\Program Files\Java\jdk1.8.0_25
CLASSPATH – .;C:\Program Files\Java\jdk1.8.0_25\lib;%CLASSPATH%;
PATH – C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.6.0_45\bin;<other paths omitted>;C:\Program Files\Java\jdk1.8.0_25\bin
The full output of set can be viewed here.
I've got a similar problem I'm currently working on solving. I can't say this will solve your error since there may be issues with other software (which is my case with Eclipse Luna).
Java is using the path given in your PATH variable, which is,
C:\ProgramData\Oracle\Java\javapath
Go to this folder (ProgramData is hidden, so unhide it if necessary) and right click on the java.exe symlink. You'll see in the Target field where it's looking for java.exe. It may be pointing to the java.exe file from your previous jdk1.6.0_45 install. Either paste in new shortcuts here or change the PATH setting as others have mentioned.
I've found that the Java installer doesn't change the javapath or update the system path, at least when going from 1.8 to 1.7. In my case changing the shortcuts only led to a problem with Eclipse on startup.
EDIT:-----
After playing with javapath folder shortcuts it turns out you need symlinks, at least for Eclipse. See, Windows how to create directory symlink.
You don't need the /d switch for a file symlink,
mklink java.exe "C:\Program Files\Java\jdk1.8.0_20\bin\java.exe"
mklink javaw.exe "C:\Program Files\Java\jdk1.8.0_20\bin\javaw.exe"
mklink javaws.exe "C:\Program Files\Java\jdk1.8.0_20\bin\javaws.exe"
This now works for me.
Why Oracle did such a poor way to point to java is beyond me. We solved this problem by creating a new link to the JDK
mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\jdk1.8.0_40\bin\"
The same would work for a JRE if that is all that is required.
This replaces the old symlinks in C:\ProgramData\Oracle\Java\javapath (if they existed previously)
I had in PATH:
C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_92\bin;<others omitted>
I removed:
C:\ProgramData\Oracle\Java\javapath;
and that fixed the issue for me. java -version now gives details about the Java version, etc.
This will solve all problems relating to Java and environment variables:
Make your way to Windows' Environment Variables dialog.
Under System variables, select the variable named Path. Click Edit...
Remove the entry that looks like:
C:\ProgramData\Oracle\Java\javapath
Add the path of your JDK/JRE's bin folder.
Don't forget to set JAVA_HOME.
I got same error while running JAVA command. To resolve this, I moved the java path as the first entry in the path, and it resolved the issue. Please have look at this screenshot for reference:
Updating the PATH Environment Variable
If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it, such as:
C:\> "C:\Program Files\Java\jdk1.8.0\bin\javac" MyClass.java
It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.8.0\bin directory to the PATH variable. Typically, this full path looks something like
C:\Program Files\Java\jdk1.8.0\bin. Set the PATH variable as follows on Microsoft Windows:
Click Start, then Control Panel, then System.
Click Advanced, then Environment Variables.
Add the location of the bin folder of the JDK installation to the PATH variable in System Variables.
The following is a typical value for the PATH variable:
C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0\bin
Note:
The PATH environment variable is a series of directories separated by semicolons (;) and is not case-sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored.
If you are not sure where to add the JDK path, append it.
The new path takes effect in each new command window you open after setting the PATH variable.
There are 2 versions of jdk in your PATH VARIABLE jdk1.6.0_45 and jdk1.8.0_25. Try removing the first one ie. jdk1.6.0_45 from the PATH
If you're on a corporate PC that's fairly restricted by group policy, this might work....
Assuming that
your Windows PATH includes C:\ProgramData\Oracle\Java\javapath
you have JDK installed to C:\Program Files\Java\jdk1.8.0_60\bin
Then create the following text file mklink.bat and put it on your desktop:
rem mklink.bat
mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\jdk1.8.0_60\bin"
pause
Now right-click it and choose "Run as Administrator". Provide admin credentials. The script should report success. Now you can compile or run Java.
This usually happens when you update the java,
the easiest way to solve this is to just uninstall the JDK & then reinstall it.
NOTE: This doesnt remove the path or classpath so no need to worry.
Uninstall all JDKs installed on your computer from the Java Control Panel
Search for C:\ProgramData\Oracle\Java and delete that directory and all files contained within. You can do this from the command line using rmdir /S C:\ProgramData\Oracle\Java
Then search for C:\ProgramData\Oracle and delete the oracle folder. You can do this using rmdir /S C:\ProgramData\Oracle
Now install JDK and set the path.
Run the program.You won't find the same problem anymore.
This problem exists when you upgrade from one version to another.because jdk is not automatically upgraded.
For the same you can change the environmental varibles.
In system variables look for the PATH and add the jdk bin location in the front of the string(not at the back).
Once you have done that check in CMD if "java" and "javac" works.
if it works, again go to system variables.
add "CLASSPATH" A the variable and set value " .
c:\Program Files\Java\jdk1.8.0_91\lib;"
There must be two or more PATH variables. Try merging all of them into one using semi-colon (;)
I got the same after installing java8 from a non-permissioned account.
To fix I simply reinstalled from admin user account.
This created the quoted directory with file links to java exes.
I had also similar problem where by I had to un-install JDK 1.8 and needed jdk 1.7.
What i did was removed the symbolic links from the javapath and then imported the shortcuts of java, javaw, javaws from the bin directory to the javapath folder. However, I found some permission issues in the enterprise laptop where by I did not have the privilege to modify/ update this directory. I had given appropriate permission from the administrator and there by resolved it.
c:\ProgramData\Java\javapath is used for symlinks. You can of course add the full path to your Java Path to %PATH%, but equally you can create a symlink to the path to the above location.
Open CMD as Administrator.
Type mklink java.exe (full path to your Java.exe)
eg
mklink java.exe "C:\Program Files\Java\jdk1.8.0_25\bin\java.exe"
Don't worry.
Just uninstall jdk as well as jdk updates
Before re installing jdk ,delete the oracle folder inside programData hidden folder in C:\
Then reinstall.
Set the following,
JAVA_HOME
CLASSPATH
PATH
JRE_HOME ( is optional)
Please remove "C:\ProgramData\Oracle\Java\javapath\java.exe" from the Path variable and add your jdk bin path. It will work.
In my case the I have removed the the above path and added my JDK path which is "C:\Program Files\Java\jdk1.8.0_221\bin"
For New version of Java JavaPath folder is located
64 bit OS
"C:\Program Files \Common Files\Oracle\Java\javapath\"
X86
"C:\Program Files(x86) \Common Files\Oracle\Java\javapath\"
This will solve all problems relating to Java and environment variables:
Make your way to Windows' Environment Variables dialog.
Under System variables, select the variable named Path. Click Edit...
Remove the entry that looks like:
C:\ProgramData\Oracle\Java\javapath
Add the path of your JDK/JRE's bin folder.
Don't forget to set JAVA_HOME.
This helped me.......:-)
For me it worked like this:
On your desktop go to Search->View advanced system settings->Environment Variables
Under System Variables look for path and click Edit.
Click on New and add the new Path and move it to the top.
To find your java path if you don't know where it is installed in cmd type where javac
<>\Common Files\Oracle\Java\javapath\ is now created as a junction, no symlinks anymore

javac not recognized even when JAVA_HOME specified

When i type javac in cmd it's not recognized , although i do have jdk 1.7installed and specified JAVA_HOME as following
c://Programfiles/Java/jdk-1.6/bin // with and without bin , with and without double slash
no result
I also tried
;c://Programfiles/Java/jdk-1.6/bin // with and without bin , with and without double slash
no result
Are there any other possible solutions
PS The System varialbes box is disabled . so i can only add user variables
By default, in order to be found by the shell, all programs have to be inside the system "path" environment variable, which is in no way related to the JAVA_HOME.
If you want configure both of them in the same time you can use the following:
set JAVA_HOME=jdk_path
set PATH=%JAVA_HOME%/bin;%PATH%
Several problems with your approach:
The environment variable JAVA_HOME has nothing to do with the mechanism that your operating system uses for finding executable files. For this the PATH variable is considered. The JAVA_HOME variable is sometimes used by other applications looking for Java.
If using the variable JAVA_HOME, it should be set to the parent directory of the bin directory.
Windows uses back slashes for separating directories, not forward slashes. (EDIT: At least, Windows 7 allows forward slashes, but I would suggest to still use back slashes.) Additionally, there is only one separator between "C:" and the the root directory.
The directory that usually contains installed programs is "Program Files", not "ProgramFiles"
Putting it all together you should do the following:
Create the environment variable JAVA_HOME with your Java installation directory as value, e.g. "C:\Program Files\Java\jdk-1.6". This directory must contain the bin directory, which in turn contains the executable files (such as java.exe).
Extend the environment variable PATH by adding ";%JAVA_HOME%\bin" at the end of it.
Both edits should be made in system variables. Now you simply can open a command prompt and check this setup with a "java -version". This should work.
EDIT
If only user variables can be edited in the environment settings, the following will work:
Add a variable JAVA_HOME to the user variables, as mentioned above.
Add a (new) variable PATH to the user variables with the content "%PATH%;%JAVA_HOME%\bin".
If you now open a command prompt and check the path variable by simply typing "path", you will see that the variables in the path are properly expanded. Now check with "java -version".
Two step process:
set JAVA_HOME=jdk_path;jdk_path\bin and
set PATH=%JAVA_HOME%
Then, to confirm, run:
java -version
What commands are or are not recognized at the command prompt has nothing to do with the JAVA_HOME environment variable, but with the PATH variable.
You can check your path in windows command line with
C:\> path
Apart from that, be sure to point to the correct jdk1.7 bin directory. It is a bad idea to call this ...Java/jdk-1.6/bin

JAVA_HOME error while 'play run' on Windows -- play framework

I am getting error while doing 'play run'
"Could not execute the Java executable, please make sure the JAVA_HOME environment variable is set properly (the Java executable should reside at JAVA_HOME/bin/java)."
But I can confirm that , JAVA_HOME is set correctly, as I am able to run 'java' command from console i.e. DOS prompt.
Can anyone please guide me on this?
Set user variable
JAVA_HOME to C:\Progra~1\Java\jdk1.7.0_04
and
extend the system variable
Path with %JAVA_HOME%\bin;
works for me
I had the same problem on Windows 7. echo %JAVA_HOME% returned C:\Programmes\Java\jdk1.7.0, which seemed correct. However, in Windows 7, even though path looks like that in explorer, the "real" path to use with cmd is C:\Program Files\Java\jdk1.7.0.
I updated JAVA_HOME and restarted cmd — otherwise, the terminal wouldn't refresh its variables — and it worked smoothly.
Being able to run java from your command line does NOT indicate that you have set the JAVA_HOME variable. Do you know how to do that?? Or do you know how to check if this variable exist?
Here is a quick way IF you are using Windows: Right click My Computer (or Computer in Windows 7) then click the tab Advanced then environment variables. In the System variables check if there is an entry with the variable JAVA_HOME. If NOT create one (by clicking new) giving JAVA_HOME in variable name and the path of your jdk in the variable value. IF let's say, your jdk is installed on the following path: c:\jdk6 in your pc THEN this should be your variable value. Click Ok, Ok again and then run your app again!
Have you done echo %JAVA_HOME%?
Several issues:
JAVA_HOME (a variable used by the JVM) is not the same than PATH (a variable used by the OS to locate directories where to find executables). Doing java.exe just shows that the bin directory of Java is in PATH, not that JAVA_HOME points where it should (or even it exists)
Also, Windows usually does not use the PATH variable, but instead treats java specially and stores its location in the register (do an echo %PATH% to check this).
In conclussion: You cannot assume JAVA_HOME is set; check for it directly and set it (Control Panel-> System -> Advanced).
Make sure you use a DOS-Path in JAVA-Home. Meaning no fakes from Win-7 C:\Programme in real C:\Program Files and no blank in path.
C:\>dir /x Prog*
09.08.2011 13:55 <DIR> PROGRA~1 Program Files
21.08.2011 20:25 <DIR> PROGRA~2 Program Files (x86)
This is a safe solution.
echo %JAVA_HOME% is indeed always a good idea to.
If you have a 64 bit Windows version, make sure you have both the 32bit and 64bit version of Java installed (so there must be a Java directory in both Program Files and Program Files (x86). That was my problem.
I updated my jdk from 1.6.0_14 to 1.7.0_10 and my jre6 to jre7 and had the same problem on XP.
I then deleted JAVA_HOME and added it again and it worked.
I also added JRE_HOME as a System Variable
JAVA_HOME --> C:\Program Files\Java\jdk1.7.0_10
JRE_HOME --> C:\Program Files\Java\jre7

Change where Java looks for javac.exe

I am trying to upload my GAE app using the console in windows. I am getting the error:
cannot find javac executable based on java.home tried, "C:\Program Files\Java\jre6\bin\javac.exe" and "C:\Program Files\Java\bi
n\javac.exe"
Unable to upload app: cannot find javac executable based on java.home, tried "C:
\Program Files\Java\jre6\bin\javac.exe" and "C:\Program Files\Java\bin\javac.exe
javac.exe is located in C:\Program Files\Java\jdk1.6.0_18\bin how do I tell java thats where it is
You must set the JAVA_HOME environment variable to refer to the top-level folder where java is installed. Right-click "My Computer", Properties, Advanced, Environment Variables. If there's an existing JAVA_HOME variable, then correct it so that its value is
C:\Program Files\Java\jdk1.6.0_18
If there is no existing variable, then create one by using the "New" button. It's up to you whether to do it for the current user or for the system.
Do you have two java versions installed?
From the information the sun jre and the Open jdk? The jre has no javac.exe and therefore cant find it.
Try to start your jar with C:\Program Files\Java\jdk1.6.0_18\bin\java.exe instead of only java, if that doesn't help add the -Djava.home="C:\Program Files\Java\jdk1.6.0_18" option to the call.
The error message makes it clear that the lookup is based on java.home, have you tried adjusting that?
This output looks like it is coming from some sort of script which may have it's own definition of java.home which you need to change.
The easiest solution for this problem which I found is to use the JAVA_HOME variable in the script file.
This is the content of my bin\appcfg.cmd:
#"%JAVA_HOME%"\bin\java -cp "%~dp0\..\lib\appengine-tools-api.jar" com.google.appengine.tools.admin.AppCfg %*
Note: you should also check if JAVA_HOME points to an existing JDK
The other way you can do set classpath variable using set CLASSPATH=C:\Program Files\Java\jre6\bin\javac.exe\jdk1.6.0_18 in command prompt, but it works for single session.Everytime you need to set the variable.
Set your JAVA_HOME environment variable to C:\Program Files\Java\jdk1.6.0_18. Note that this variable points to the JDK location, not (unlike the PATH environment variable) to the path where the executables reside.

Categories