添加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 ...
随机推荐
- 添物不花钱学JavaEE(基础篇)-XML
XML(Extensible Markup Language) XML在日常工作中经常用到,必须有个了解,不过认识一下即可,不要太浪费时间.实际用到 参考图书 <XML入门经典>大而全,不 ...
- table 设置自动宽度后 td 的固定宽度 在 谷歌浏览器自动拉伸
table 设置自动宽度后 td 的固定宽度 在 谷歌浏览器自动拉伸 解决方案 <table style="table-layout:fixed;">
- [K/3Cloud] 隐藏菜单后,如何在插件间接的调用隐藏菜单的操作
使用场景: 动态表单里面挂了个单据的序时薄,序时薄有菜单,但是把序时薄的工具栏隐藏了.新增,修改全部动态表单自己写.删除和过滤我想间接调用下隐藏的序时薄的删除和过滤按钮的操作.在插件里如何实现? 答: ...
- 贪吃的九头龙(tyvj P1523)
T2 .tyvj P1523贪吃的九头龙 描述 传说中的九头龙是一种特别贪吃的动物.虽然名字叫“九头龙”,但这只是说它出生的时候有九个头,而在成长的过程中,它有时会长出很多的新头,头的总数会远大于 ...
- 2018/4/7 Mybatis源码结构概览
在观看Mybatis源码的过程中,有一点疑惑,就是Mybatis的缓存设计明显有问题,首先,Mybatis缓存分为两级,先说一级,生命周期为一个sqlsession,只有在查询相同方法时才会命中缓存, ...
- msp430入门学习00
在TI官网上找到MSP430的程序例程.数据手册.使用指南等文件.以MSP430F169为例,步骤如下: 1)进入ti官网:http://www.ti.com.cn/ 或者http://www.ti. ...
- Thinkphp5.0 的视图view的模板布局
Thinkphp5.0 的视图view的模板布局 使用include,文件包含: <!-- 头部 --> <div class="header"> {inc ...
- 用jQuery向div中添加Html文本内容
前台代码: <link href="http://www.cnblogs.com/Content/themes/base/jquery-ui.css" rel="s ...
- hdu - 1104 Remainder (bfs + 数论)
http://acm.hdu.edu.cn/showproblem.php?pid=1104 注意这里定义的取模运算和计算机的%是不一样的,这里的取模只会得到非负数. 而%可以得到正数和负数. 所以需 ...
- jackson的应用
直接上代码 package com.demo.jackson.utils; import com.fasterxml.jackson.core.JsonProcessingException; imp ...