添加tomcat开机启动服务时报错:Neither the JAVA_HOME nor the JRE_HOME enviromment variable is defined
首先,参考的 https://blog.csdn.net/wabil/article/details/78818249 的方式添加 tomcat 开机启动,这种方式不需要添加 setenv.sh 文件,轻量级,非常方便,具体方式如下:
1. 创建一个服务文件
vim /lib/systemd/system/tomcat.service 复制如下内容,修改后保存:
[Unit]
Description=tomcat
After=network.target [Service]
Type=oneshot
ExecStart=/home/apache-tomcat-7.0.70/bin/startup.sh // 自已的tomcat目录
ExecStop=/home/apache-tomcat-7.0.70/bin/shutdown.sh // 自已的tomcat目录
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes [Install]
WantedBy=multi-user.target
2. 启动服务
systemctl start tomcat.service
执行这步的时候,始终报启动失败,执行下面步骤查看失败原因。
3. 查看服务状态
systemctl status tomcat.service

没理由 JAVA_HOME 和 JRE_HOME 不存在啊,明明是存在的,检查一下发现确实是存在的:

解决方法:
方法1. 在 tomcat/bin/setclasspath.sh 中添加 JAVA_HOME 和 JRE_HOME 的指向(试了一下,不知道什么原因没搞成功)
# -----------------------------------------------------------------------------
# Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
# are valid and consistent with the selected start-up options and set up the
# endorsed directory.
# -----------------------------------------------------------------------------
#
24 # JAVA_HOME=/usr/java/jdk1.8.0_171
25 # JRE_HOME=/usr/java/jdk1.8.0_171/jre
方法2. 在 tomcat.service 中添加 JAVA_HOME 和 JRE_HOME 的指向(推荐)
Environment='JAVA_HOME=/usr/java/jdk1.8.0_171'
Environment='JRE_HOME=/usr/java/jdk1.8.0_171/jre'
此时再次执行服务启动命令 systemctl start tomcat.service 成功,服务运行状态如下:

附完整的 tomcat.service 文件
[Unit]
Description=Tomcat
After=network.target [Service]
Type=forking
Environment='JAVA_HOME=/usr/java/jdk1.8.0_171'
Environment='JRE_HOME=/usr/java/jdk1.8.0_171/jre'
ExecStart=/opt/my/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/opt/my/tomcat/shutdown.sh
RemainAfterExit=yes [Install]
WantedBy=multi-user.target
4. 设置为开机启动
systemctl enable tomcat.service
添加tomcat开机启动服务时报错:Neither the JAVA_HOME nor the JRE_HOME enviromment variable is defined的更多相关文章
- 普通用户操作tomcat项目时报:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
在使用普通用户更新tomcat项目适合出现这个信息,Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At ...
- python paramiko ssh.exec_command()启动tomcat服务器应用进程失败问题解决方法- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this progr
问题说明:
- Tomcat9+JDK 13报错Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
Tomcat使用的是https://tomcat.apache.org/download-90.cgi Tomcat9 之前安装的JDK 13,有JAVA_HOME环境变量地址(C:\Program ...
- 启动tomcat 报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
[root@localhost META-INF]# systemctl start tomcat Job for tomcat.service failed because the control ...
- tomcat启动报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable
linux 下 启动tomcat 报: Neither the JAVA_HOME nor the JRE_HOME environment variable is definedAt least o ...
- tomcat启动报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
windows系统: 部署了一个Tomcat8.5.15,bin目录下startup.bat执行,结果提示Neither the JAVA_HOME nor the JRE_HOME enviro ...
- Jenkins启动Tomcat时提示Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
Jenkins构建提示: [SSH] executing...Neither the JAVA_HOME nor the JRE_HOME environment variable is defi ...
- linux安装tomcat Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
这两天我们的开发机重启了好几次,发现每次重启后我的tomcat总是没有启动.检查java路径,配置正确,后来拿普通账号启动tomcat时报如下的错: Neither the JAVA_HOME nor ...
- Java项目启动时候报Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 解决办法
今天在发布Java项目的时候又遇到 Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At leas ...
随机推荐
- caca需要用到x11作为图形输出
编译错误:no output drivers were selected!. yum -y install xcb-proto yum -y install libxcb-devel.x86_64 l ...
- HDU1074 Doing Homework 状态压缩dp
题目大意: 根据完成任务的截止时间,超时一天罚1分,求完成所有任务后的最小罚时 这里n最大为15,可以利用状态压缩来解决问题 /* 首先要明白的一点是状态1/0分别表示这件事做了还是没做 而1/0的位 ...
- [HDU2136] Largest prime factor(素数筛)
传送门 题意 给出若干个数n(n<=1000000),求每个n的最大质因子的排名. 质数的排名:如果素数p是第k小的素数,那么p的排名就是k. 思路 乍一看不知道怎么搞. 其实可以想想我们怎么筛 ...
- bzoj3304[Shoi2005]带限制的最长公共子序列 DP
题意:给出三个序列,求出前两个的公共子序列,且包含第三个序列,要求长度最长. 这道题目怎么做呢,f[i][j]表示a串1-i,b串1-j的最长,g[i][j]表示a串i-n,b串j-m最长, 那么只需 ...
- springData Jpa 快速入门
前言: 数据持久化的操作,一般都要由我们自己一步步的去编程实现,mybatis通过我们编写xml实现,hibernate也要配置对应的xml然后通过创建session执行crud操作.那么有没有这样一 ...
- 详解SpringBoot集成jsp(附源码)+遇到的坑
本文介绍了SpringBoot集成jsp(附源码)+遇到的坑 ,分享给大家 1.大体步骤 (1)创建Maven web project: (2)在pom.xml文件添加依赖: (3)配置applica ...
- LOJ#541. 「LibreOJ NOIP Round #1」七曜圣贤
有一辆车一开始装了编号0-a的奶茶,现有m次操作,每次操作Pi在[-1,b),若Pi为一个未出现过编号的奶茶,就把他买了并装上车:若Pi为一个在车上的奶茶,则把他丢下车:否则,此次操作为捡起最早丢下去 ...
- codevs4439 YJQ Requires Food
题目描述 Description 神犇YJQ有n个不同的妹子和m种食物,每一天每一种食物只供应一个妹子吃的份量.在接下来的t天内,YJQ准备包养所有的妹子. 对于每个妹子,她在t天内都只会吃某些特定的 ...
- POJ 2240_Arbitrage
题意: 给定一系列货币汇率,求能否从一种货币,经过一系列转换,最终转化回更高价值的该种货币. 分析: 即为求最长路并判断是否存在"正"权值回路,这里用的bellmanford算法. ...
- MongoDB小结15 - find【查询条件$ne】
$ne表示不相等 db.user.find({"name":{"$ne":"william"}})