雄猫 6 JAVA_HOME

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18468681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:52:36  来源:igfitidea点击:

Tomcat 6 JAVA_HOME

javatomcatbatch-filetomcat6

提问by QuinsUK

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

我尝试设置 JAVA_HOME 路径,因为我的 Tomcat 服务器正在寻找它。我正在尝试设置它,但它似乎不起作用并在我这样做时导致错误。我正在尝试在 setclasspath.bat 中使用设置 JAVA

set JAVA_HOME="C:\Program Files (x86)\Java\jre7"

This is at the start of the setclasspath.bat

这是在 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

当我设置它并运行“startup.bat start”时它会显示

Files was unexpected at this time

此时文件意外

Can you help me?

你能帮助我吗?

采纳答案by James Corcoran

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_26or 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.

您指向的是 JRE。您需要指向一个 JDK,鉴于您的 JRE 的位置可能类似C:\Program Files (x86)\Java\jdk1.6.0_26或类似。或者,如果您只安装了 JRE,则需要安装完整的 JDK。Tomcat 需要能够将 JSP 编译成 .class 文件,而 JRE 无法做到这一点。

回答by Jesse

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.

该错误是由于它将 Program Files 中的文件解析为一个单独的参数,这是 SET 不期望的。为什么 SET 不能正确读取它我不能说不知道更多关于你正在使用的操作系统,你正在运行 Tomcat 的命令 shell,等等。

回答by You_Shall_Not_Pass

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..

您的命令失败的原因是它在“程序文件(x86)”之间有空格,因此它开始从“文件(x86)”中读取命令。所以我们把它放在双引号之间,如下所示。尝试这个..

set JAVA_HOME="C:\"Program Files (x86)"\Java\jre7"

回答by Stephen Clothier

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.

我在具有以下定义的 Windows 7 上遇到了同样的问题(我将它放在由 tomcat 7 的 RUNNING.txt 指定的 jdk bin 文件夹中的 setenv.bat 文件中。

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.

然后tomcat启动了。

回答by Douglas G. Allen

Try https://askubuntu.com/questions/446294/how-to-start-tomcat7-when-catalina-sh-does-not-workIt 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

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

回答by Douglas G. Allen

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 notneed a JDK to run, it will work just fine with a JRE, as long as it knows it's a JRE.

首先:Tomcat不需要运行 JDK,只要它知道它是 JRE,它就可以与 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.

其次,原始问题的错误来自set JAVA_HOME=...命令的语法问题。Apache 自己可以通过剥离和添加"引号更好地处理它。

Also, I would highly recommend creating a setenv.batfile in the binfolder. 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.

另外,我强烈建议setenv.batbin文件夹中创建一个文件。默认情况下它不存在,因此如果您还没有,请创建它并在那里添加您的set JAVA_HOME=...set JRE_HOME=...行。

Run with JRE

使用 JRE 运行

As per running.txt:

根据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.

JRE_HOME 变量用于指定 JRE 的位置。JAVA_HOME 变量用于指定 JDK 的位置。

使用 JAVA_HOME 可以访问使用 JRE_HOME 时不允许的某些附加启动选项。

如果同时指定了 JRE_HOME 和 JAVA_HOME,则使用 JRE_HOME。

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_HOMEvariable is a failsafe, but it's not really required. As per the docs, Tomcat will try use the JRE variable first anyway.

清除JAVA_HOME变量是一种故障保护,但这并不是真正必需的。根据文档,无论如何 Tomcat 都会首先尝试使用 JRE 变量。

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"".

将输出""hello"".

set "%TEST%=hello"
echo "%TEST%"

Will output "hello".

将输出"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".

因此,启动批处理文件脚本试图使用""C:\Program Files (x86)\Java\jre7"",其中第一个非转义空间位于“程序”和“文件”之间。

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 andvalue in quotation marks.

正如已经指出的那样,删除引号(至少在这种特殊情况下)会起作用,但依赖于它是危险的。而是从一开始就安全地使用它,并将变量名称值用引号括起来。

回答by tk_

  • 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 setlocaland before rem Guess CATALINA_HOME if not defined
  • 首先安装java并定位到安装路径。
  • 找到tomcat安装路径,在\bin中找到startup.bat
  • 打开 startup.bat 并在setlocal前后添加以下(示例)行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%
:: 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

现在尝试重新运行 startup.bat

回答by Adarsh J

  • If not able to set the variables manually: to set JAVA_HOME and JRE_HOME

  • go to advance system setting and click on environmentvariables

  • under systemvariables click

  • new variable name : JAVA_HOME
  • variable value : [path of jdk]C:\Program Files\Java\jdk1.8.0_181and 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
  • 如果无法手动设置变量:设置 JAVA_HOME and JRE_HOME

  • 转到高级系统设置并单击environment变量

  • system变量下单击

  • 新变量名: JAVA_HOME
  • 变量值:[path of jdk]C:\Program Files\Java\jdk1.8.0_181然后单击确定

  • 同样添加 JRE_HOME

  • 单击新变量名称: JRE_HOME
  • 变量值: [path of jre]C:\Program Files\Java\jre1.8.0_181
  • 点击Ok> Ok>Ok