Tomcat is not running even though JAVA_HOME path is correct
Asked Answered
H

18

24

When I am trying to run tomcat using startup.bat I get the following error,

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

But then I try C:\>echo %java_home% and I get the following result

C:\Program Files\Java\jdk1.6.0_25\bin

I have even tried setting JAVA_HOME manually to system variable list, but this issue remains.

What can I do to solve it?

I am using Windows 7.


Update

After setting a new system variable named JAVA_HOME and setting its path to "C:\Program Files\Java\jdk1.6.0_25\bin\", I tried the start up script again and this time I get a new error.

D:\Work\apache-tomcat-6.0.35\bin>startup.bat
Files\Java\jdk1.6.0_25"" was unexpected at this time.

Any idea what this error means?

I even tried setting the path to "C:\Program Files\Java\jdk1.6.0_25\"(that is without bin) but same error occurs.

Highgrade answered 13/1, 2012 at 23:37 Comment(4)
Check if startup.bat is redefining that environment variable. Look for "SET JAVA_HOME ... "Finicking
@luciano no, there is no re-definition of JAVA_HOME.Highgrade
are there any spaces in your JAVA_HOME? Also did you get your echo result correctly or is it just a copy/paste mistake?Ichinomiya
@zenzen yes, it was c/p mistake. I have updated the question as well.Highgrade
I
32

Try installing java somewhere else - in a directory without spaces. Set again the JAVA_HOME variable and try again. I remember Tomcat had some problems on Window XP with spaces if any variables it was using while starting contained spaces. Maybe it's similar with Windows 7.

I remember I had to change some lines in Tomcat java classes which were handling Tomcat startup.

@Edit: Luciano beat me to noticing it but you should also remove bin from JAVA_HOME

@Edit: I also remember that another fix (didn't test it myself, though) was to set JAVA_HOME to the shorthand version e.g. C:\Progra~1\Java\jdk1.6.0_25

Ichinomiya answered 13/1, 2012 at 23:53 Comment(8)
If you see my updated question I think you have just hit it. Files\Java\jdk1.6.0_25 means its the last part of Program Files. So, I guess its white space issue. Is there any escape character that I can use in the path to solve this, without going to install/uninstall.Highgrade
I think its a tomcat issue. What makes you think its related to windows?Highgrade
Because it works on *NIX systems :) From what I remember there's a line in one of the java classes written by Tomcat guys which doesn't properly handle spaces, so yeah it kinda is a Tomcat issue but only on Windows systems, if I remember correctly.Ichinomiya
Problem solved I re installed on a different location without white space. This is very annoying when a high profile product has this type of messy issues.Highgrade
Just to clarify to other users coming to this site, that the JDK can be perfectly installed on a path that contains white spaces and Tomcat runs just fine using it.Finicking
I get this same issue and I have no spaces in either JAVA_HOME not PATH.Ballocks
@Finicking I can verify Luciano's comment. I just had the same issue as the OP and I am using Tomcat 7.0.47 with JRE 1.7.0. I took the quotes out of my CATALINA_HOME, CATALINA_BASE, and JRE_HOME (no JDK installed on this box). Taking the quotes off let me run Tomcat with the following command: %CATALINA_HOME%\bin\startup.bat Presocratic
Using the "no-spaces" version of the path works great. Thanks for this answer!Ghibelline
F
19

I think that your JAVA_HOME should point to

C:\Program Files\Java\jdk1.6.0_25

instead of

C:\Program Files\Java\jdk1.6.0_25\bin

That is, without the bin folder.

UPDATE

That new error appears to me if I set the JAVA_HOME with the quotes, like you did. Are you using quotation marks? If so, remove them.

Finicking answered 13/1, 2012 at 23:55 Comment(4)
If you know its the right thing, then why would it make you think? :PHighgrade
I find it more politely to say it that way.Finicking
I am using tomcat 7.0.62. The only change that I had to make was to install latest version of JRE and after that everything worked smoothly. I installed jre1.8.0_60 and the problem got solved.Cornaceous
@Finicking - This is really late to comment on your comment, but when you say "I think" just to be "polite", you are actually saying (to many readers) that you are not certain of the answer. This causes the reader to doubt your answer ... which is a bad thing (if it is in fact correct). In writing StackOverflow answers, it is more important to be clear than to be polite. (And besides, in many cultures, saying "I think ..." has no connotations of politeness or modesty at all.) In short, Quazi makes a valid point.Admiration
N
9

Avoid semicolon in the end of any environment variables... from JAVA_HOME or JRE_HOME

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_25\bin

and

JRE_HOME=C:\Program Files\Java\jdk1.6.0_32\jre

should be like as shown...

Neurasthenia answered 8/5, 2012 at 4:46 Comment(0)
R
6

I had Win 8 x86 installed. My Path variable had entry C:\Program Files\Java\jdk1.6.0_31\bin and I also had following variables:

  • JAVA_HOME : C:\Program Files\Java\jdk1.6.0_31;
  • JRE_HOME : C:\Program Files\Java\jre6;

My tomcat is installed at C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.41

And still it did not worked for me.

I tried by replacing Program Files in those paths with Progra~1. I also tried by moving JAVA to another folder so that full path to it does not contain any spaces. But nothing worked.

Finally environment variables that worked for me are:

  • Kept path variable as is with full Program Files i.e. C:\Program Files\Java\jdk1.6.0_31\bin
  • JAVA_HOME : C:\Program Files\Java\jdk1.6.0_31
  • Deleted JRE_HOME

So what I did is removed JRE_HOME and removed semicolon at the end of JAVA_HOME. I think semicolon should not be an issue, though I removed it. I am giving these settings, since after a lot of googling nothing worked for me and suddenly these seem to work. You can replicate and see if it works for you.

This also worked for Win 7 x64, where

  • Path variable contained C:\Program Files (x86)\Java\jdk1.7.0_17\bin
  • JAVA_HOME is set to C:\Program Files (x86)\Java\jdk1.7.0_17 (without semicoln)

Please tell me why this worked, I know removing JRE_HOME was weird solution, but any guesses what difference it makes?

Rainie answered 30/9, 2013 at 15:43 Comment(1)
As said for me the same, finally your solution got workedCompassion
S
2

Remove the 'bin' from JAVA_HOME. That solves the issue.

Selfloading answered 26/7, 2013 at 21:50 Comment(0)
B
1

Set Environment Variable ([Windows Key]+[Pause Key], switch to "Advanced", click "Environment Variables", in "System Variables" (lower list), click "New" (or "Edit" if you already have it),

name: JAVA_HOME

value: C:\PROGRA~1\Java\JDK16~1.0_3

for C:\Program Files\Java\jdk1.6.0_32

click "ok",

go to "path" in "system variables",

add ; at the end of the line (unless there is already one there),

add: C:\PROGRA~1\Java\JDK16~1.0_3\bin

click "ok" through all. -- restart your computer (advisable)

Banebrudge answered 31/5, 2012 at 21:7 Comment(0)
H
0

I set the

variable name : JAVA_HOME value : C:\Program Files\Java\jdk1.6.0_32

I set these properties in system/environment variables without semicolon, tomcat is running on my system.

It really works.

Hearty answered 12/6, 2012 at 17:44 Comment(0)
C
0

Also ensure that you have the correct version of Tomcat for the CPU type. I had installed a 64bit tomcat on a 32bit O/S but it was giving me the JAVA_HOME exception when that wasn't the case at all.

Colenecoleopteran answered 14/2, 2013 at 12:13 Comment(0)
M
0

there are two types of environment variable first User variable if you path in this it will work for that particular user only. second is System variable if you set path in this it is used by all type of users.. In my system i set JAVA_HOME in system variable,it was not working,then i set path in User variable it is working.....so try in both type of environment variable...

Moeller answered 12/10, 2013 at 16:58 Comment(0)
J
0

Some times semiColon makes matter please ensure

JAVA_HOME=c:\Program Files\Java\jdk1.6.0_32 

but not

JAVA_HOME=c:\Program Files\Java\jdk1.6.0_32;

Same problem i got but not solved

Jog answered 14/3, 2014 at 8:57 Comment(0)
E
0

Set environment variables for JAVA_HOME and JRE_HOME without the \bin. That worked for me

Endomorph answered 29/8, 2014 at 5:30 Comment(0)
A
0

I deleted the Tomcat and unzipped it again and it worked.

Andrien answered 20/1, 2015 at 14:21 Comment(0)
M
0

To run Tomcat8 you need to have JRE_HOME defined in Env Variable.

JAVA_HOME alone will not do even if correctly set.

JRE_HOME = C:\Program Files\Java\jdk1.8.0_77\jre

You should select the JRE that is inside SDK, i.e. one with your JDK(SDK) installation. In other words your JAVA_HOME + \jre

When compiling JDK is needed to support JSP, to compile Servlets which are generated from *.jsp files. Otherwise to run JRE is needed. So when you develop you need JAVA_HOME and when you deploy you need JRE_HOME.

Madian answered 27/6, 2016 at 13:9 Comment(0)
A
0

For reference for me with Atlassian's Bamboo the issue was because I had wrapped the command in speech marks

So

SET JRE_HOME="C:\Program Files\Java\jre1.8.0_121"

Was wrong, where as the right version is

SET JRE_HOME=C:\Program Files\Java\jre1.8.0_121

This gave me the error message

Files\Java\jre1.8.0_121"" was unexpected at this time.
Amino answered 8/3, 2017 at 15:13 Comment(0)
U
0

Check the comparability, if you are using java 8 then use tomcat 9, if you are using java 7 then use tomcat 7. and also set the JAVA_HOME till C:\Program Files\Java\jdk1.8.0_101, not with bin.

Unknowing answered 17/12, 2019 at 6:57 Comment(0)
A
-1
First Run the tomcat directly through the tomcat /bin folder with 
startup.bat if running sucessful the set the variable as below sample    

JAVA_HOME value : C:\Program Files\Java\jdk1.6.0_32;

path: C:\Program Files\Java\jdk1.6.0_32\bin;

CATALINA_HOME=C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27 ;

PATH=%PATH%;%JAVA_HOME%\bin;%CATALINA_HOME%\bin;

if needed CLASS_PATH:%CATALINA_HOME%\lib;%JAVA_HOME%\lib;

Alyse answered 26/10, 2013 at 7:32 Comment(1)
previous answer was unacceptable . Thanks for the Suggestion.Alyse
N
-1

Remove semicolon and you can see that link: http://www.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html

Nephrosis answered 6/2, 2015 at 23:15 Comment(1)
Please don't only post link answers. Just put the essential parts of the link in your answerHirokohiroshi
B
-2

I had similar problem and please note that we need not set JAVA_HOME unless we are going to use debug mode. tomcat in windows 7 can handle spaces in environment variables the problem is because of "bin" in the path. setting JRE_HOME to C:\Program Files (x86)\Java\jre1.8.0_65 solved my problem and tomcat is up and running without any trouble

Baumgardner answered 23/10, 2015 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.