简体   繁体   中英

Tomcat 6 JAVA_HOME

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"

试试https://askubuntu.com/questions/446294/how-to-start-tomcat7-when-catalina-sh-does-not-work它可以给你一些见解,即使它不是 Windows 它仍然会寻找那些 shell 脚本除了它们在 Window 中的扩展名是 .bat 而不是 .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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM