首先,参考的 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的更多相关文章

  1. 普通用户操作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 ...

  2. 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

    问题说明:

  3. 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 ...

  4. 启动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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. linux安装tomcat Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

    这两天我们的开发机重启了好几次,发现每次重启后我的tomcat总是没有启动.检查java路径,配置正确,后来拿普通账号启动tomcat时报如下的错: Neither the JAVA_HOME nor ...

  9. 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 ...

随机推荐

  1. HASH的应用(负数下标用偏移量解决)

    Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个处于区间[-500000,500000]的整数. Output 对每组测试数据按从大到小的 ...

  2. bzoj 1962 硬币游戏 (猜数问题)

    [bzoj1962]模型王子 2015年3月26日1,6460 Description Input 输入数据共一行,两个整数N,K,用一个空格隔开,具体意义如题目中所述. Output 输出数据共一行 ...

  3. 【NOIP2016】天天爱跑步(树上差分)

    题意: 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.?天天爱跑步?是一个养成类游戏,需要 玩家每天按时上线,完成打卡任务.这个游戏的地图可以看作一一棵包含 N个结点 ...

  4. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...

  5. 06-js的逻辑结构

    <html> <head> <title>js的逻辑结构和循环结构学习</title> <meta charset="UTF-8&quo ...

  6. HttpClientUtil 工具类 实现跨域请求数据

    package com.xxx.common.util; import java.io.IOException; import java.net.URI; import java.util.Array ...

  7. java生成xml

    import java.io.File;import java.io.FileOutputStream;import java.text.SimpleDateFormat;import java.ut ...

  8. Sqlserver数据库发送邮件

    目录 1. Sqlserver数据库发送邮件 1.1. 概念了解 1.2. 配置 1.3. 测试发送邮件 1.3.1. 代码测试 1.3.2. 工具测试 1.4. 查看邮件日志 1. Sqlserve ...

  9. base64加解密字符串

    import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOExceptio ...

  10. angular 的ui.router 定义不同的state 对应相同的url

    Angular UI Router: Different states with same URL? The landing page of my app has two states: home-p ...