简体   繁体   English

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

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

I'm trying to set up Tomcat 6 on my server instance (Fresh install of Windows Server 2008 R2 Enterprise).我正在尝试在我的服务器实例上设置 Tomcat 6(全新安装的 Windows Server 2008 R2 Enterprise)。 I want to make a Java EE service available via a URL.我想通过 URL 提供 Java EE 服务。

It works via localhost on the server.它通过服务器上的localhost工作。 I put the .war file in my /webapps , run startup.bat in the /bin and then i navigated to localhost:80/myWebServce in my browser to get directed to my welcome page.我将 .war 文件放在我的/webapps ,在/bin运行 startup.bat 然后我在浏览器中导航到localhost:80/myWebServce以定向到我的欢迎页面。

When I try to create a service by running service.bat (in the /bin folder)) 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).我认为 JDK 只是一个 JRE + 一些开发工具(IDE、调试器等)。 Why does tomcat need a JDK To run as a service, but not on localhost?为什么 tomcat 需要一个 JDK 来作为服务运行,而不是在 localhost 上运行? What's in a JDK that's needed to run a webservice?运行 Web 服务所需的 JDK 中有什么?

remove semi-colon from the end of JRE_HOME / JAVA_HOME variables.从 JRE_HOME / JAVA_HOME 变量的末尾删除分号。 there should not be semi-colon…不应该有分号……

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。

Tomcat does not require a JDK. Tomcat 不需要 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 附带了 Eclipse JDT 编译器,Tomcat 使用该编译器作为 *.jsp -> *.java -> *.class 进程的一部分将 JSP 转换为已编译的 Servlet。

However, if you specify JAVA_HOME, Tomcat expects that to point to a full JDK installation.但是,如果您指定 JAVA_HOME,Tomcat 期望它指向完整的 JDK 安装。 If you want to use a JRE then you need to set JRE_HOME rather than JAVA_HOME.如果要使用 JRE,则需要设置 JRE_HOME 而不是 JAVA_HOME。

I had the same problem.我有同样的问题。 Specified JRE_HOME and received the same error message.指定 JRE_HOME 并收到相同的错误消息。 The error message persisted after I had removed the system environment variable JAVA_HOME and rebooted.删除系统环境变量 JAVA_HOME 并重新启动后,错误消息仍然存在。 Turned out my JRE path was actually incorrect, the error message was just confusing.原来我的 JRE 路径实际上是不正确的,错误消息只是令人困惑。

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

Make JAVA_HOME as system variable instead of environment variable, restart application(Tomcat).将 JAVA_HOME 作为系统变量而不是环境变量,重新启动应用程序(Tomcat)。 It should work fine.它应该可以正常工作。

Alternatively you might be facing same issue as discussed here或者,您可能面临与此处讨论的相同的问题

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.是的,我们需要 jdk 才能运行您的要求..因为您提供 .war 文件,我们需要 jar 命令从 war,jar.. 文件中提取内容。 jar command is not found in JRE but only in JDK. jar 命令在 JRE 中找不到,而只能在 JDK 中找到。 if you wish you can checkout JDK,JRE.如果您愿意,可以查看 JDK、JRE。 that is basic thing i observed apart from other things.这是我观察到的基本的东西。

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.检查 JAVA_HOME 是否设置正确,如果您安装了 JDK,则为 jre 创建 JRE_HOME,将为 JDK 设置 JAVA_HOME。 Also alternate between "C:/Progra~1/..." and "C:/Program Files/..." to make sure the system is recognizing the path correctly还可以在"C:/Progra~1/...""C:/Program Files/..."之间交替以确保系统正确识别路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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