OK, what am I doing wrong, this is driving me nuts.
I am trying to install the latest JDK (1.6.0_23). So, I downloaded it from Oracle's awful site and then ran the installation. I installed it to C:\Java\jdk1.6.0_23
Then, I created a JAVA_HOME User Variable that pointed to C:\Java\jdk1.6.0_23. I then added a piece to the end of my Path environment variable that says %JAVA_HOME%\bin.
However, when I try to simply open a command prompt and run simple java commands, I am told it is not a recognizable command. I have to manually cd into the that bin directory to do anything.
Do I also need a Classpath variable that points to the JRE? I noticed there was a Classpath variable there previously that pointed to jre/lib/QTJava.zip, but I deleted it.
If you have the JDK installed and a JAVA_HOME variable setup, do I still need the JRE in the classpath? I am running Windows 7 and do all of my development in Eclipse.
Maybe the problem is because you set JAVA_HOME as a user variable, but trying to reference it from the PATH which is a system variable (or is it?). You cannot do this, because system variables are evaluated before user variables.
There are two possible solutions:
1. Set JAVA_HOME as a system variable instead
2. Create a new user variable PATH and set %JAVA_HOME%\bin there. The user PATH and the system PATH variables will be concatenated at runtime automatically.
From http://social.answers.microsoft.com/Forums/en-US/vistainstall/thread/48b23109-9fbc-47c5-a5d1-465773f94704
(at the end)
1) Enable 'delayed variable expansion'
in the registry (see
http://batcheero.blogspot.com/2007/06/how-to-enabledelayedexpansion.html)
2) Change the '%' signs around var2 to
'!', e.g. "%var2%" becomes "!var2!"
I've done some limited testing on
Windows 7 and this appears to fix the
problem.
Maybe try that, see if it fixes it (I don't have windows here to try)
Do I also need a CLASSPATH variable that points to the JRE?
Strictly speaking, no. The CLASSPATH variable may be used if you try to run a java class and you don't use the -cp or -jar options.
The CLASSPATH variable doesn't need to point to the JRE. The java.exe command etc all know where to find the JRE's runtime classes. (And they don't look on the CLASSPATH for them anyway.)
For the PATH problem, try running:
C:\Java\jdk1.6.0_23\bin\java.exe -version
If that doesn't work then there's a problem with your actual installation. If it does work, try looking at what JAVA_HOME and PATH are set to in the environment variables of the command shell.
Related
When trying to check the current version of Java in which I am running, I received the error "java is not recognized as an internal or external command, operable program or batch file.".
I am running Windows 7 OS and have downloaded the latest JDK and felt I may have accidentally deleted the java from machine as before I was able to check the Java version using the command "java -version".
What software must I download to get Java working on my machine again?
EDIT:
I have managed to get Java running from my cmd again after ensuring all environment variables pointed to the current Java SDK.
You need to configure your environment variables, JAVA_HOME and PATH.
JAVA_HOME must contain the path to java, and you should add %JAVA_HOME%\bin to PATH
Alternatively, you can simply add to your PATH the whole path to the bin folder, without the JAVA_HOME variable, however, this makes a little more annoying when you need to have more than one java version on your machine (that way you only need to change JAVA_HOME and don't even bother with PATH)
For Windows 7:
Right click on My Computer
Select Properties
Select Advanced System Settings
Select the Advanced tab
Select Environment Variables
Select Path under System Variables
Click on the Edit button
In Variable value editor paste this at the start of the line
C:\Program Files\Java\jdk1.7.0_72\bin;
Click Ok then Ok again
Restart command prompt otherwise it won't see the change to the path variable
Type java -version in the command prompt.
Notes on Step 8:
The version of java in this may be different from the one used here -- this is only an example.
There will probably be other values in the path variable. It is really important that you don't delete what's already there. That's why the instructions say to paste the given value at the start of the line -- this means that you don't remove the existing value, you just put java before it. This also fixes any problems you'd be getting if an other version of java is also on the path.
Notes on Step 6:
This sets the path for the computer, not for the individual user. It may be that you're working on a computer which other developers also use, in which case you'd rather set the user variables, rather than the system variables
It sounds like you haven't added the right directory to your path.
First find out which directory you've installed Java in. For example, on my box it's in C:\Program Files\java\jdk1.7.0_111. Once you've found it, try running it directly. For example:
c:\> "c:\Program Files\java\jdk1.7.0_11\bin\java" -version
Once you've definitely got the right version, add the bin directory to your PATH environment variable.
Note that you don't need a JAVA_HOME environment variable, and haven't for some time. Some tools may use it - and if you're using one of those, then sure, set it - but if you're just using (say) Eclipse and the command-line java/javac tools, you're fine without it.
1 Yes, this has reminded me that I need to update...
Assume, Java/JDK is installed to the folder: C:\Program Files\Java:
Follow the steps:
Goto Control Panel → System → Advanced system settings → Advanced → Environment variables (Win+Pause/Break for System in Control Panel)
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\bin, press OK:
In the System variables section double click on Path
Press New and write C:\Program Files\Java\bin, press OK:
In Environment variables window press OK
Restart/Run cmd.exe and write: java --version:
Search environment variables.
open the "edit the system environment variables".
then click on "environment variables".
Under "User variables" click on "Path" then "Edit".
Find your Java path and click "Edit".
then paste the path of your java installation folder.
Mostly you can find it on a path similar to this.
C:\Program Files\Java\jdk-12.0.2\bin
Then click OK.
now in the start menu, type cmd.
open the command prompt.
type
java -version
If you did it right,it should show something like this.
For me its start working after putting ,: in the starting of the system variable path :--
My solution was to put same value (path to JDK bin folder) in JAVA_HOME and Path
In my case, PATH was properly SET but PATHEXT has been cleared by me by mistake with .exe extension. That why window can't find java or anything .exe application from command prompt. Hope it can help someone.
This problem is on Windows 8.
First copy your Path of java jdk - e.g. C:\Program Files\Java\jdk1.7.0_51\bin.
Right on the My Computer Icon on the Desktop and Click Properties.
Select 'Advanced System Settings' in the left pane.
Under 'Advanced' tab, select 'Environment Variables' at the bottom.
In System Variables, select 'Path' Variable and edit it.
Paste the path and add a ';' at the end - e.g. C:\Program Files\Java\jdk1.7.0_51\bin;
I had the same problem. Just Install the exact bit of java as of your computer. If your PC is 64 bit then install 64 bit java. If it is 32 bit then vice versa :)
Not sure why, but in my case, the reason was because I was running Anaconda terminal instead of the CMD.
After I use CMD and update the path settings as mentioned by all comments above the issue solved on my side.
In case you are using a laptop and do not have the Pause\Break button.
For windows 10 users with 20h2 and above:
1 WIN → type "About your PC" → scroll at the bottom → Advanced system settings → Environment variables or WIN+R → shell:::{bb06c0e4-d293-4f75-8a90-cb05b6477eee} to open Classic System Properties → on the left side → Advanced system settings → Environment variables
Also for Windows 10 and Windows 7:
1 WIN → This PC → properties → Advanced system settings → Environment variables
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\jdk-15.0.2\bin, press OK
I have taken steps 2-4 from Vijay Bhatt
There is a bit faster way to set a system variable. Run a console (terminal) as an administrator.
General command synax to add a new variable:
setx variableName value /M
In our example, we would need to set it as
setx JAVA_HOME "C:\Program Files\Java\jdk-15.0.2\bin" /M`
Like this:
/M - flag specifies to set the variable in the system environment.
After command execution, you should see the message:
SUCCESS: Specified value was saved.
How can I check that it is added?
Close your active terminal;
Open your favorite terminal;
Type java -version.
You should see something similar to this:
Notice:
User variables can be created w/o having a root (administrator privileges), whereas to create System variable; You need to open a console as a root.
I have used C:\Program Files\Java\jdk-15.0.2\bin as an example, in your case, it could be different from mine.
I opened a new command prompt in Windows 10 after updating the environment variables without closing the old one(To have my commands handy and lazy to type again)
Still, the new cmd window was referring to the previous version of Java.
Then once I closed the all cmd prompts that ran with admin privileges, the new java version was getting reflected.
I corrected my path variable but command prompt need to Restart otherwise, it won't be able to verify the change to the path variable. May be helpful for someone like me. so
"restart command prompt"
Restart the command prompt before checking the version of JDK installed. I spent 02 days on it until my problem resolved when I restarted the command prompt before checking javac - version, javac etc.
if you have cygwin installed in the Windows Box, or using UNIX Shell then
Issue bash#which java
This will tell you whether java is in your classpath or NOT.
If you have set the environment variables (JAVA_HOME and PATH) under user variables, command prompt (run as administrator) will not identify java. For that you need to set environment variables under system variables.
Try this:
System variables:
PATH = /bin folder of your jdk install
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm
Just some extra information for people that have still problems,
instead of editing the path variable of java, delete that part of the path(only the java!!)
and make a new variable pointing tpo the jdk/jre.
this seemed to work for me.
I try to set the JAVA_HOME path as my Tomcat server is looking for it. I am trying to set it but it doesn't seem to work and causes an error when I do. I am trying to set the JAVA in the setclasspath.bat using
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
This is at the start of the setclasspath.bat
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo At least one of these environment variable is needed to run this program
goto exit
When I set this and run "startup.bat start" it displays
Files was unexpected at this time
Can you help me?
Note: I realise this is already quite an old question, but many of the answers posted here are either incomplete or inaccurate.. Hopefully this will help save a few headaches.
Firstly: Tomcat does not need a JDK to run, it will work just fine with a JRE, as long as it knows it's a JRE.
Secondly, the error from the original question is coming from an issue with syntax of the set JAVA_HOME=... command. Apache themselves could handle it better with stripping and adding " quote marks.
Also, I would highly recommend creating a setenv.bat file in the bin folder. It's absent by default, so if you don't already have one, create it and add your set JAVA_HOME=... or set JRE_HOME=... lines there.
Run with JRE
As per running.txt:
The JRE_HOME variable is used to specify location of a JRE. The
JAVA_HOME variable is used to specify location of a JDK.
Using JAVA_HOME provides access to certain additional startup options
that are not allowed when JRE_HOME is used.
If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.
So, to startup this way, you'll need the following:
set "JAVA_HOME="
set "JRE_HOME=C:\Program Files (x86)\Java\jre7"
Clearing the JAVA_HOME variable is a failsafe, but it's not really required. As per the docs, Tomcat will try use the JRE variable first anyway.
Solution for Issue in Question
Take special note the position of the quotation marks. This way keep the entire string together in one variable, without including the quotation marks in the variable content itself.
For example:
set %TEST%="hello"
echo "%TEST%"
Will output ""hello"".
set "%TEST%=hello"
echo "%TEST%"
Will output "hello".
So, the startup batch file script was trying to use ""C:\Program Files (x86)\Java\jre7"", in which the first non-escaped space is between "Program" and "Files".
As already pointed out, removing the quotation marks (in this particular case at least) would work, but it's dangerous to rely on that. Rather play it safe from the start and wrap the variable name and value in quotation marks.
I had the same problem on Windows 7 with the following definition (I put it in a setenv.bat file in the jdk bin folder as specified by tomcat 7's RUNNING.txt.
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
I just tried removing the double quotes altogether:
set JAVA_HOME=C:\Program Files (x86)\Java\jre7
And tomcat then started.
First, install java and locate the instalation path.
Locate the tomcat installation path and find the startup.bat in \bin
Open startup.bat and add below(example) lines just after setlocal and before rem Guess CATALINA_HOME if not defined
:: JAVA
set JAVA_HOME=D:\thushara_data\Java\jdk1.8.0_73
set PATH=%JAVA_HOME%\bin;%PATH%
Now try to re-run startup.bat
Place the path in quotes:
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
The error is due to the fact that it's parsing the Files in Program Files as a separate parameter, which SET doesn't expect. Why SET isn't reading it properly I can't say without knowing more about what OS you're using, what command shell you're running Tomcat from, and so on.
If not able to set the variables manually:
to set JAVA_HOME and JRE_HOME
go to advance system setting and click on environment variables
under system variables click
new variable name : JAVA_HOME
variable value : [path of jdk]C:\Program Files\Java\jdk1.8.0_181 and click ok
similarly add JRE_HOME
click new variable name : JRE_HOME
variable value : [path of jre]C:\Program Files\Java\jre1.8.0_181
click Ok > Ok > Ok
You are pointing to a JRE. You need to point to a JDK, which given the location of your JRE might be something like C:\Program Files (x86)\Java\jdk1.6.0_26 or similar. Or, if you only have a JRE installed, you'll need to install a full JDK. Tomcat needs to be able to compile JSPs into .class files, which a JRE can't do.
The reason why your command failed is because it has white spaces between 'Program Files (x86)' and so it starts reading the command from 'Files (x86)'. So instead we put it in between double quotes such as the following.
try this..
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
Try
https://askubuntu.com/questions/446294/how-to-start-tomcat7-when-catalina-sh-does-not-work
It can give you some insight even though it's not Windows it still looks for those shell scripts except their extensions in Window is .bat not .sh
You Can Also Try This For jre1.8v:
Open cmd In Tomcat Server Folder And Enter Command
set "JAVA_HOME=C:\Program Files (x86)\Java\jre1.8.0_45"
Then Enter Command cd bin
Then To Start Tomcat Server Enter Command startup
To Stop Tomcat Server Enter Command shutdown
If It Fails To Start Although You Can Run Command: cd startup.bat
I have Ubuntu 10.10 with java already installed. I am able to execute java command from any folder. I supposed that could be because I had java Classpath setted. But neither JAVA_HOME nor CLASSPATH are setted.
If I look at /etc/environment content I can see that PATH is setted to /usr/bin/ (among others). As 'which java' returns /usr/bin/java, is that the reason why I can execute java from anywhere? If not, why is it?
You can execute java because the command is on your path.
echo $PATH
will show you which directories are searched, in which order to find a particular program. Since /usr/bin is on your path, when you type java it will eventually look at /usr/bin/java. Note that in many systems this is a symbolic link (a file that points to another file) so /usr/bin/java often points to /etc/alternatives/java (which is also a symbolic link that points to the real executable).
Where the environmental variable JAVA_HOME comes into play is in tools and programs that check for JAVA_HOME and act on it instead of relying on the path. In most modern Linux systems, the work done by the alternatives subsystem replaces the earlier (more problematic) JAVA_HOME technique. That said, you might want to set JAVA_HOME anyway, should you encounter a tool that demands it.
One reason why JAVA_HOME is not as popular as it could be is that to access JAVA_HOME you need to run a shell, and not everyone wants to wrap every single Java item in a shell command.
Yes, if java binary (or a link to it) is on a folder that is listed on the path then you can execute java without specifying the path to it (for example /usr/local/java/latest/bin/java -jar x.jar)
JAVA_HOME and CLASSPATH have nothing to do with system path.
JAVA_HOME allow other software (or scripts) to know where to look for java installation.
CLASSPATH tells java where to look for classes (.class files resulting of compiling .java files).
I do most of my work against JDK 1.5 - but occasionally I have to change to 1.6. it is a bit painful to have to manually go and change my 'JAVA_HOME' system variable whenever I need to work on a project specific to one or the other (and no, Eclipse doesn't play well in these scenarios - trust me...I've tried.)
I'm looking for a registry script or windows shell script or for that matter any means by which I can "toggle" this system variable with something that is easy to run.
I've messed with the 'set' command, but that only sets the variable for that particular command instance - not globally.
Thanks in advance.
EDIT #1:
Points of advise:
Use the JAVA_HOME variable in your path variable as well, that way you only have to change the JAVA_HOME (which is used in many projects anyways [maven, ant, etc])
Write the command into a couple batch scripts for easy use
When you make the change the windows command session will not reflect it right away. You must close and reopen it.
You could use setx for that purpose
Like so:
setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17"
What can I do when I keep receiving the error
'javac' is not recognized as an internal or external command, operable program or batch file
when I want to compile my jar or .class file?
Thanks
Make sure %JAVA_HOME%/bin is on your %PATH% (or $JAVA_HOME on the $PATH in *nix).
It means that it is not in your path. You have the following options:
1) Change to the directory where javac lives before calling it.
2) Use the full path to javac when making the call, e.g. C:\java\jdk1.6.0_12\bin\javac ...
3) Add the javac directory to the PATH environment variable
This just means that javac isn't in your PATH variable.
On Windows, you just have to add the folder that contains javac.exe to the PATH environment variable (Win+Pause/Break).
On Linux/Mac/Unix, just append that directory to $PATH in .bashrc or similar.
The error that you are seeing is generated by Windows, and isn't specific to Java. That error means that you typed a command and Windows could not find the command by that name.
The easiest way of rectifying the situation is to ensure that Java is properly installed in your system's PATH.
First, ensure that you have a JDK installed (and not just a JRE). Your next best bet is to add an environment variable called JAVA_HOME and point it at the base install directory for the version of Java that you installed.
Next, modify your PATH environment variable by prepending the string %JAVA_HOME%\bin; to whatever is already in your PATH. If you look at the contents of that directory, you will see that javac is in there (along with a number of other Java development tools).
You have to install JDK (which includes javac compiler) and ensure that it's in the path. See http://java.sun.com/javase/downloads/index.jsp
Common Error Messages from SUN Tutorial page
Step 4 (Update the PATH variable) of the JDK installation instructions explains what you should do to make it so that you can just type javac in the command prompt window.
The link below gives a step by step explanation on how to set up java_home and path variables.
JAVA_HOME setup
Even if I had
JDK installed
JAVA_HOME defined
%JAVA_HOME%\bin present in my %PATH%
I still had this error. I resolved it by eliminating the JRE from my path variable. It was put before JAVA_HOME, has no javac. It seems Windows can't find javac in JAVA_HOME\bin in this case.
For Windows
Control Panel > System...Then click Advanced System Setting (left pane)...then popup window will open...then click Environment Variables...Then another window will open...click New and add enter information below
Variable name: PATH
Variable value: C:\Program Files\Java\jdk1.7.0_45\bin [*make sure this is the right path for you]
Then it should work
Check whether you have JDK installed; if not installed, Install
If JDK is installed, navigate into the bin folder of the installation, and try to execute javac.
If javac executes, proceed (+:
If javac does not execute, check your system path, and java path, and return to 2 above!