Windows 2012R2下的Java环境变量

时间:2021-05-15 23:03:18

We are trying to run Apache-Tomcat which would start / stop as a service. However, when trying to set it up, we get error messages as for unset variables, making it impossible to set it as a service. Looking at the file, and given that this is a .BAT file, as provided by the distribution, is there an easy way to set the JAVA-HOME and other required variables for Java to be set globally for the box ? Our main challenge is to get Apache-Tomcat copied / setup through a script, and the environment variables globally (and permanently) set so that when the server is rebooted, or the service started/stopped/restarted.

我们正在尝试运行Apache-Tomcat,它将作为服务启动/停止。但是,在尝试设置时,我们会收到有关未设置变量的错误消息,从而无法将其设置为服务。查看该文件,并且假设这是一个.BAT文件,由发行版提供,是否有一种简单的方法来设置JAVA-HOME和其他所需的Java变量全局设置?我们的主要挑战是通过脚本复制/设置Apache-Tomcat,并全局(和永久)设置环境变量,以便在重新启动服务器或启动/停止/重新启动服务时。

1 个解决方案

#1


1  

The JAVA_HOME environment variable is only used when running the service.bat file. Once the service has been created, it has embedded the value, so changing a global JAVA_HOME environment variable will make no difference.

JAVA_HOME环境变量仅在运行service.bat文件时使用。一旦创建了服务,它就嵌入了值,因此更改全局JAVA_HOME环境变量将没有任何区别。

When you want to use a different JAVA_HOME value, you have to deregister the service and reregister with the new value.

如果要使用其他JAVA_HOME值,则必须取消注册该服务并使用新值重新注册。

This is regardless of Windows version. Also remember to run service.bat "as admin".

这与Windows版本无关。还记得运行service.bat“as admin”。


There is a good reason why a registered Tomcat instance is not using global environment values. As an example, we're running 6 different Tomcat instances on our UAT server, each with a different combination of Tomcat version and Java version. We couldn't do that if all the instances were using a single global JAVA_HOME or CATALINA_HOME value.

注册的Tomcat实例没有使用全局环境值是有充分理由的。例如,我们在UAT服务器上运行了6个不同的Tomcat实例,每个实例都有不同的Tomcat版本和Java版本组合。如果所有实例都使用单个全局JAVA_HOME或CATALINA_HOME值,则无法执行此操作。

#1


1  

The JAVA_HOME environment variable is only used when running the service.bat file. Once the service has been created, it has embedded the value, so changing a global JAVA_HOME environment variable will make no difference.

JAVA_HOME环境变量仅在运行service.bat文件时使用。一旦创建了服务,它就嵌入了值,因此更改全局JAVA_HOME环境变量将没有任何区别。

When you want to use a different JAVA_HOME value, you have to deregister the service and reregister with the new value.

如果要使用其他JAVA_HOME值,则必须取消注册该服务并使用新值重新注册。

This is regardless of Windows version. Also remember to run service.bat "as admin".

这与Windows版本无关。还记得运行service.bat“as admin”。


There is a good reason why a registered Tomcat instance is not using global environment values. As an example, we're running 6 different Tomcat instances on our UAT server, each with a different combination of Tomcat version and Java version. We couldn't do that if all the instances were using a single global JAVA_HOME or CATALINA_HOME value.

注册的Tomcat实例没有使用全局环境值是有充分理由的。例如,我们在UAT服务器上运行了6个不同的Tomcat实例,每个实例都有不同的Tomcat版本和Java版本组合。如果所有实例都使用单个全局JAVA_HOME或CATALINA_HOME值,则无法执行此操作。