Creative crypter
Creative crypter

Reputation: 1496

Apache Tomcat - Ubuntu Setup

In order to get tomcat working on my ubuntu, i downloaded "apache-tomcat-8.5.4.tar.gz"-file

Next i decompressed it and moved it to an other location:

tar -xvzf apache-tomcat-8.5.4.tar.gz
sudo mkdir -p /opt/tomcat
sudo mv apache-tomcat-8.5.4 /opt/tomcat/

I also added some variables to system:

export JAVA_HOME=/usr/lib/java/jdk1.8.0_102
export CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.4
export PATH="$PATH:$JAVA_HOME/bin"

sourced it:

source .profile

When i run:

java -version

it correctly prints:

1.8.0_102 .. etc

But when i run:

sudo $CATALINA_HOME/bin/startup.sh

it fails with message:

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

Anybody could refer to this issue?

Thanks and Greetings!

Upvotes: 0

Views: 947

Answers (2)

Ray Hunter
Ray Hunter

Reputation: 15557

The issue is that you are running sudo and the environment is not setup properly.

I would add the following exports to the /etc/environment file so that they are system wide.

export JAVA_HOME=/usr/lib/java/jdk1.8.0_102 
export CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.4 
export PATH="$PATH:$JAVA_HOME/bin"

Then edit the sudoers file with sudo visudo and add this to the file:

Defaults env_keep += "JAVA_HOME CATALINA_HOME"

That will allow you to run the sudo command and have the environment setup properly. I would not recommend modifying the catalina.sh script.

Upvotes: 0

Cesar Villasana
Cesar Villasana

Reputation: 687

Try having this configuration inside your $CATALINA_HOME/bin/catalina.sh:

JAVA_HOME=/usr/lib/java/jdk1.8.0_102

CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.4

Put it as the first two lines of the file so it can use it later on.

Hope it helps

Upvotes: 1

Related Questions