在服务器上设置 Tomcat 7:“注意:JAVA_HOME 应该指向 JDK 而不是 JRE”......为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20469317/
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-13 02:10:35  来源:igfitidea点击:

Setting up Tomcat 7 on server: "NB: JAVA_HOME should point to a JDK not JRE"... Why?

javatomcatconfiguration

提问by Paul

I'm trying to set up Tomcat 6 on my server instance (Fresh install of Windows Server 2008 R2 Enterprise). I want to make a Java EE service available via a URL.

我正在尝试在我的服务器实例上设置 Tomcat 6(全新安装的 Windows Server 2008 R2 Enterprise)。我想通过 URL 提供 Java EE 服务。

It works via localhoston the server. I put the .war file in my /webapps, run startup.bat in the /binand then i navigated to localhost:80/myWebServcein my browser to get directed to my welcome page.

它通过localhost在服务器上工作。我将 .war 文件放在我的 .war 文件中/webapps,在其中运行 startup.bat/bin然后我localhost:80/myWebServce在浏览器中导航到我的欢迎页面。

When I try to create a service by running service.bat (in the /binfolder)) I get an error message that says:

当我尝试通过运行 service.bat(在/bin文件夹中)来创建服务时,我收到一条错误消息:

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

My question is: Why? I thought a JDK was just a JRE + Some development tools(an IDE, a debugger etc). Why does tomcat need a JDK To run as a service, but not on localhost? What's in a JDK that's needed to run a webservice?

我的问题是:为什么?我认为 JDK 只是一个 JRE + 一些开发工具(IDE、调试器等)。为什么 tomcat 需要一个 JDK 来作为服务运行,而不是在 localhost 上运行?运行 Web 服务所需的 JDK 中有什么?

采纳答案by Mark Thomas

Tomcat does not require a JDK. Tomcat ships with the Eclipse JDT compiler which Tomcat uses as part of the *.jsp -> *.java -> *.class process to convert JSPs to compiled Servlets.

Tomcat 不需要 JDK。Tomcat 附带了 Eclipse JDT 编译器,Tomcat 使用它作为 *.jsp -> *.java -> *.class 进程的一部分将 JSP 转换为已编译的 Servlet。

However, if you specify JAVA_HOME, Tomcat expects that to point to a full JDK installation. If you want to use a JRE then you need to set JRE_HOME rather than JAVA_HOME.

但是,如果您指定 JAVA_HOME,Tomcat 期望它指向完整的 JDK 安装。如果要使用 JRE,则需要设置 JRE_HOME 而不是 JAVA_HOME。

回答by dev2d

Web containers require JDK in order to support compilation of sources like JSP, as compiler is existing in JDK it requires the same.(this is one of the reasons why it may require JDK)

Web 容器需要 JDK 才能支持 JSP 等源代码的编译,因为 JDK 中存在编译器,因此它也需要相同的编译器。(这是它可能需要 JDK 的原因之一)

回答by Dark Knight

Make JAVA_HOME as system variable instead of environment variable, restart application(Tomcat). It should work fine.

将 JAVA_HOME 作为系统变量而不是环境变量,重新启动应用程序(Tomcat)。它应该可以正常工作。

Alternatively you might be facing same issue as discussed here

或者,您可能面临与此处讨论的相同的问题

回答by anilkumar

yes we require jdk inorder to run your requirement.. since you are providing .war file , we need jar command to extract contents from war,jar.. files. jar command is not found in JRE but only in JDK. if you wish you can checkout JDK,JRE. that is basic thing i observed apart from other things.

是的,我们需要 jdk 才能运行您的要求..因为您提供 .war 文件,我们需要 jar 命令从 war,jar.. 文件中提取内容。jar 命令在 JRE 中找不到,而只能在 JDK 中找到。如果您愿意,可以查看 JDK、JRE。这是我观察到的基本的东西。

回答by Daniel

Check that the JAVA_HOME is set up correctly and if you have JDK installed create JRE_HOME for jre, JAVA_HOME would be set up for the JDK. Also alternate between "C:/Progra~1/..."and "C:/Program Files/..."to make sure the system is recognizing the path correctly

检查 JAVA_HOME 是否设置正确,如果您安装了 JDK,则为 jre 创建 JRE_HOME,将为 JDK 设置 JAVA_HOME。之间交替显示"C:/Progra~1/...",并"C:/Program Files/..."确保系统正确识别路径

回答by Bennani HAMZA

remove semi-colon from the end of JRE_HOME / JAVA_HOME variables. there should not be semi-colon…

从 JRE_HOME / JAVA_HOME 变量的末尾删除分号。不应该有分号……

variable: JAVA_HOME value : C:\Program Files\Java\jdk1.6.0 (note : no semicolon at the end)

变量:JAVA_HOME 值:C:\Program Files\Java\jdk1.6.0(注意:末尾没有分号)

variable: JRE_HOME value : C:\Program Files\Java\jre1.6.0 (note : no semicolon at the end)

变量:JRE_HOME 值:C:\Program Files\Java\jre1.6.0(注意:末尾没有分号)

Apply above changes and run your tomcat successfully.

应用以上更改并成功运行您的 tomcat。

回答by 20GETitDONE90

I had the same problem. Specified JRE_HOME and received the same error message. The error message persisted after I had removed the system environment variable JAVA_HOME and rebooted. Turned out my JRE path was actually incorrect, the error message was just confusing.

我有同样的问题。指定 JRE_HOME 并收到相同的错误消息。删除系统环境变量 JAVA_HOME 并重新启动后,错误消息仍然存在。原来我的 JRE 路径实际上是不正确的,错误消息只是令人困惑。