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.