文档章节

Change JRE for Tomcat的四种方法

五大三粗
 五大三粗
发布于 2015/12/15 12:56
字数 605
阅读 79
收藏 0

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

Basically, an installation of Tomcat is running under the default JRE which can be found based on environment variables ( JAVA_HOME ), or registry entries (on Windows) or the JRE is specified during installation (Tomcat is installed as a service). Sometimes we need to change the default JRE for Tomcat, either for testing purposes or to run Tomcat under a targeted version of JRE. In this article, we summarize different ways to change JRE for a Tomcat installation. To know which JRE version is used for Tomcat, go to the following URL:

localhost:8080/manager/status

And look at the JVM Version column: See JVM version for Tomcat  

1. Changing JRE by updating JAVA_HOME or JRE_HOME

This way is very simple to implement but it works only for Tomcat installed from a zip distribution (in contrast to Tomcat installed as a service).
    • If only the JAVA_HOME environment variable is set, Tomcat will run under the JRE as part of the JDK specified by theJAVA_HOME variable. Therefore, we change JRE for Tomcat by updating this variable.
    • If both the JAVA_HOME and JRE_HOME environment variables are set, the JRE_HOME is preferred. Here’s an example of a valid value for the JRE_HOME variable (path on Windows):

JRE_HOME=C:\Program Files\Java\jre7

Notice that updating the  JAVA_HOME  or  JRE_HOME  environment variables will affect all the applications that depend on them, so if you want to look for a more independent approach, see the second way as described below.  

2. Changing JRE by using “setenv” script

We can change the JRE for Tomcat by setting the  JRE_HOME  variable in a script file called  setenv.bat  (on Windows) or setenv.sh  (on *nix). This file does not exist by default, so create such file and place it under  CATALINA_BASE\bin  directory ( CATALINA_BASE  is the Tomcat installation directory).
On Windows, create the  setenv.bat  file with the following content:
1
2
set "JRE_HOME=C:\Program Files\Java\jdk1.7.0_03\jre"
exit /b 0
  On *nix, create the  setenv.sh  file with the following content:
1
2
JRE_HOME=/usr/java/jdk1.7.0_03/jre
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
  Note that this way only works with Tomcat installed from a zip distribution. It doesn’t apply for Tomcat installed as a service. Behind the scenes, the Tomcat’s start up script ( startup.bat / startup.sh ) will invoke the “setenv” script if it is present. One advantage of this way is that it doesn’t affect the system environment variables.  

3. Changing JRE in Tomcat service manager

For a Tomcat installation which is installed as a service (on Windows), we can change the version of JRE that runs Tomcat by configuring the  Java Virtual Machine  setting in the Tomcat service manager program (e.g. Tomcat7w.exe), as shown in the following screenshot: Change JVM for Tomcat This way is very simple to perform, and it does not depend on the system environment variables  JAVA_HOME  or  JRE_HOME .  

4. Changing JRE in Eclipse IDE

If you are using Tomcat inside Eclipse IDE, changing the JRE version for Tomcat is also pretty easy. By default, Tomcat is running under the same JRE as Eclipse (Workbench default JRE). To change JRE version for a Tomcat runtime in Eclipse, go to the menu  Window > Preferences . In the  Preferences  dialog, open the  Server > Runtime Environments  node, select a Tomcat version in the list, and then click the  Edit  button: Edit Tomcat runtime in Eclipse The  Edit Server Runtime Environment  dialog appears, select the targeted JRE version under the JRE list: Change JRE for Tomcat in Eclipse Click  Finish  to close this dialog, and click  OK  to close the Preferences dialog. Now restart Tomcat to see the effect. Note that we can spot the JRE version by looking at the  Console  view as shown below: JRE version in Console view

© 著作权归作者所有

五大三粗
粉丝 164
博文 2293
码字总数 4767276
作品 0
广州
程序员
私信 提问
Tomcat启动时卡在“INFO: Deploying web application directory ......”的解决方法

第一次遇到Tomcat在Linux服务器启动卡住的情况,情况很简单,tomcat启动以后卡在INFO: Deploying web application directory ......这句话,具体会卡多久就没测试了。google、baidu都没找到解...

江南红衣
2016/12/18
143
0
Apache Tomcat 9.0.13 和 8.5.35 发布,支持 TLSv1.3

Apache Tomcat 是 Java Servlet、JavaServer Pages、Java 表达式语言和 Java WebSocket 技术的开源实现,是一个免费的开放源代码的 Web 应用服务器。 Apache Tomcat 9.0.13 更新内容: supp...

王练
2018/11/09
2.4K
8
java-buildpack源码分析之Compile

bin/compile 入口是:bin/compile,该脚本和detect脚本很类似:需要一个构建目录实例化buildpack对象,并调用其compile接口。 注意:在这个脚本看似只有一个参数,但运行时实际需要第二个参数...

wenqi_arthur
2015/10/27
29
0
java-buildpack源码分析之Detect

Detect 该buildpack的探测的内容包含:容器,JRE,框架。具体内容在components.yml中可以看到: # Configuration for components to use in the buildpack containers:- "JavaBuildpack::Co......

wenqi_arthur
2015/10/27
19
0
javax.net.ssl.SSLHandshakeException(Cas导入证书)

一.报错:javax.net.ssl.SSLHandshakeException 二.原因分析: CAS部署时,常常要涉及到HTTPS的证书发布问题。由于在实验环境中,CAS和应用服务常常是共用一台PC机,它们跑在相同的JRE环境和...

派卡琪安
2013/09/04
23.6K
0

没有更多内容

加载失败,请刷新页面

加载更多

JVM性能调优的6大步骤,及关键调优参数详解

JVM内存调优 对JVM内存的系统级的调优主要的目的是减少GC的频率和Full GC的次数。 1.Full GC 会对整个堆进行整理,包括Young、Tenured和Perm。Full GC因为需要对整个堆进行回收,所以比较慢,...

一只会编程的狼
10分钟前
4
0
并发和并行性有什么区别?

并发和并行性有什么区别? 示例被赞赏。 #1楼 并发性:具有共享资源潜力的多个执行流 例如:两个线程争用一个I / O端口。 平行主义:将问题分成多个相似的块。 例如:通过在文件的每半部分上...

javail
12分钟前
4
0
(推荐使用)提高开发效率工具集合

提高开发效率工具集合(推荐使用) 一、Hutool工具类 官网地址:https://www.hutool.cn/ Github地址:https://github.com/looly/hutool/ Gitee 地址:https://gitee.com/loolly/hutool/ 文档参...

明德先生
16分钟前
4
0
java并发-缓存一致性协议和内存屏障的思考和理解

################这是之前的思考 内存屏障只是保证清空流水线,如何保证高速缓存的内容更新到最新或刷新到主存呢?这个问题突然想到了,不知道这个需要怎回答。 内存屏障保证的CPU执行执行序...

萧默
19分钟前
5
0
类型名称后面的括号是否与new有所不同?

如果“测试”是普通类,则之间是否有任何区别: Test* test = new Test; 和 Test* test = new Test(); #1楼 new Thing(); 很明显,您想要一个构造函数,而new Thing; 表示您不介意是否未调...

技术盛宴
43分钟前
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部