sudo 啟動tomcat報錯沒有java環境
報錯:
Cannot find ./catalina.sh
The file is absent or does not have execute permission
This file is needed to run this program
原因:
沒有給bin目錄下的檔案授權可執行許可權:
解決方法:
chmod +x bin/*.sh
報錯Neither the JAVA_HOME nor the JRE_HOME environment variable is defined:
解決方法如下:
tomcat啟動指令碼檔案: startup.sh, startup.sh會載入 catalina.sh , catalina.sh會載入setclasspath.sh
Linux: export JAVA_HOME=絕對路徑 Windows: set
可以直接新增到第二行:
#!/bin/sh
export JAVA_HOME=/usr/local/java1.8
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
成功
[[email protected] apache-tomcat-8.0.43]# sudo bin/startup.sh
/home/report/apache-tomcat-8.0.43/bin/catalina.sh:行143: -Xmx1024m: 未找到命令
Using CATALINA_BASE: /home/report/apache-tomcat-8.0.43
Using CATALINA_HOME: /home/report/apache-tomcat-8.0.43
Using CATALINA_TMPDIR: /home/report/apache-tomcat-8.0.43/temp
Using JRE_HOME: /home/jdk-10.0.1
Using CLASSPATH: /home/report/apache-tomcat-8.0.43/bin/bootstrap.jar:/home/report/apache-tomcat-8.0.43/bin/tomcat-juli.jar
Tomcat started.
以上是在catalina.sh檔案中新增的。依然存在問題,就是關閉指令執行報錯 shutdown.sh
[[email protected] apache-tomcat-8.0.43]# sudo bin/shutdown.sh
/home/report/apache-tomcat-8.0.43/bin/catalina.sh:行143: -Xmx1024m: 未找到命令
Using CATALINA_BASE: /home/report/apache-tomcat-8.0.43
Using CATALINA_HOME: /home/report/apache-tomcat-8.0.43
Using CATALINA_TMPDIR: /home/report/apache-tomcat-8.0.43/temp
Using JRE_HOME: /home/jdk-10.0.1
Using CLASSPATH: /home/report/apache-tomcat-8.0.43/bin/bootstrap.jar:/home/report/apache-tomcat-8.0.43/bin/tomcat-juli.jar./catalina.sh: 1: eval: usrjjdk-10.0.1re/bin/java: not found
還是顯示找不到,而且路徑 usrjdk-10.0.1jre莫名奇妙少了 '/' 。
解決方法:
把剛剛修改的 export JAVA_HOME環境變數改寫到 setclasspath.sh裡面,把原先的 catalina.sh export那個刪除掉
成功解決:
[[email protected] apache-tomcat-8.0.43]# sudo bin/shutdown.sh
/home/report/apache-tomcat-8.0.43/bin/catalina.sh:行143: -Xmx1024m: 未找到命令
Using CATALINA_BASE: /home/report/apache-tomcat-8.0.43
Using CATALINA_HOME: /home/report/apache-tomcat-8.0.43
Using CATALINA_TMPDIR: /home/report/apache-tomcat-8.0.43/temp
Using JRE_HOME: /home/jdk-10.0.1
Using CLASSPATH: /home/report/apache-tomcat-8.0.43/bin/bootstrap.jar:/home/report/apache-tomcat-8.0.43/bin/tomcat-juli.jar