java tomcat7 不会在启动时运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13018446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:10:31  来源:igfitidea点击:

tomcat7 wont run on startup

javatomcatubuntuamazon-ec2amazon-web-services

提问by Marcus

Tried everything but it just wont work, im running tomcat7 on an EC2 instance (amazon AWS). I can start up tomcat7 manually by starting startup.sh, but not automatically on startup. The error message I get in logs/catalina.out is the following:

尝试了所有方法,但它不起作用,我在 EC2 实例(亚马逊 AWS)上运行 tomcat7。我可以通过启动 startup.sh 手动启动 tomcat7,但不能在启动时自动启动。我在 logs/catalina.out 中收到的错误消息如下:

/etc/apache-tomcat-7.0.32/bin/catalina.sh: 1: eval: /etc/jdk1.7.0_07/bin/java: not found

My enviroment variables are also setup properly:

我的环境变量也设置正确:

echo $JAVA_HOME -> /etc/jdk1.7.0_07/bin/java
echo $PATH -> /usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/sbin:/bin:/usr/games:/etc/jdk1.7.0_07/bin

I can also type "java -version" in shell getting proper output, however "/etc/jdk1.7.0_07/bin/java -version" does not work and only returns "No such file or directory".

我也可以在 shell 中输入“java -version”以获得正确的输出,但是“/etc/jdk1.7.0_07/bin/java -version”不起作用并且只返回“没有这样的文件或目录”。

Im really not sure what to do now, feels like i tried everything, hope someone can help me! Also the instance is running Ubuntu server 12.04.

我真的不知道现在该怎么办,感觉我什么都试过了,希望有人能帮助我!此外,该实例正在运行Ubuntu 服务器 12.04

采纳答案by Amit Deshpande

Do sudo su vi /etc/bash.bashrcand copy following

执行sudo su vi /etc/bash.bashrc并复制以下内容

JAVA_HOME=/etc/jdk1.7.0_07 //you have to only specify path until java dir not bin
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

回答by user1936595

I do not particularly known about specifics of ubuntu+tomcat7 on EC2. So my answer could be missing a point a bit. It is given from generic ubuntu point of view.

我不是特别了解 ubuntu+tomcat7 在 EC2 上的细节。所以我的回答可能会漏掉一点。它是从通用 ubuntu 的角度给出的。

Possibly things will be a bit easier to manage if you use apt-get to manage tomcat and java on ubuntu. In that case the tomcat will automatically started on start up. The commands below are tested on ubuntu 12.10, but also worked on some earlier version.

如果您在 ubuntu 上使用 apt-get 管理 tomcat 和 java,可能事情会更容易管理一些。在这种情况下,tomcat 将在启动时自动启动。下面的命令在 ubuntu 12.10 上测试过,但也适用于一些早期版本。

To install Java you need the following:

要安装 Java,您需要以下内容:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

If the first command fails, use the following:

如果第一个命令失败,请使用以下命令:

sudo apt-get install software-properties-common

Then install tomcat7 using:

然后使用以下命令安装 tomcat7:

sudo apt-get install tomcat7

After that you need to tell tomcat to use installed java 7. For that purpose modify /etc/default/tomcat7 file either manually or using command like the following:

之后,您需要告诉 tomcat 使用已安装的 java 7。为此,手动或使用如下命令修改 /etc/default/tomcat7 文件:

cat /etc/default/tomcat7 | sed 's/#JAVA_HOME=\/usr\/lib\/jvm\/openjdk-6-jdk/JAVA_HOME=\/usr\/lib\/jvm\/java-7-oracle/' >/tmp/tomcat7-updated
sudo cp /tmp/tomcat7-updated /etc/default/tomcat7

After that tomcat should load on start up. You just need to tune up ports and other configuration information. Note that this tomcat uses /var/lib/tomcat7/webapps/ to store web applications. You could also start or stop tomcat manually using the commands like the following:

之后,tomcat 应该在启动时加载。您只需要调整端口和其他配置信息。请注意,此 tomcat 使用 /var/lib/tomcat7/webapps/ 来存储 Web 应用程序。您还可以使用如下命令手动启动或停止 tomcat:

sudo /etc/init.d/tomcat7 start

回答by Keyser Soze

The hint for me was modifying the shell script file (set JAVA_HOME variable) and this resolved the issue.

我的提示是修改 shell 脚本文件(设置 JAVA_HOME 变量),这解决了问题。

The tomcat script file is generally under /etc/init.d/directory

tomcat脚本文件一般在/etc/init.d/目录下

回答by deepika.agrwal

For automatic startup of tomcat, it should be started during booting time only.

对于tomcat的自动启动,它应该只在启动时启动。

For that you need to write a script which starts the tomcat and put this file in the etc/init.d or you can put it for different runlevels.

为此,您需要编写一个脚本来启动 tomcat 并将此文件放在 etc/init.d 中,或者您可以将其放在不同的运行级别。