Java – JDK environment variable with Tomcat (Ubuntu 12.04)

In Ubuntu, I set up the JDK environment (java_home, jre_home), and Java version can be used

>No Java defined_ Home also has no JRE defined_ Home environment variables > at least one of these environment variables is required to run this program

Environment settings / etc / profile

JAVA_HOME=/opt/jvm/java/jdk1.7.0_25
JRE_HOME=/opt/jvm/java/jdk1.7.0_25/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME
export JAVA_HOME
export JRE_HOME
export PATH

journal

sunshanming@sunshanming-vm1:~$sudo /opt/apache-tomcat-7.0.42/bin/startup.sh 
[sudo] password for sunshanming: 
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
sunshanming@sunshanming-vm1:~$echo $JAVA_HOME
/opt/jvm/java/jdk1.7.0_25
sunshanming@sunshanming-vm1:~$echo $JRE_HOME
/opt/jvm/java/jdk1.7.0_25/jre
sunshanming@sunshanming-vm1:~$java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01,mixed mode)

Solution

Try setenv. In the Tomcats bin folder Set variables in SH That's where you specify the environment for Tomcat

Just in Tomcat / bin / setenv SH to create this file

#!/bin/bash
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
export CATALINA_OUT=/var/log/tomcat/catalina.out
export CATALINA_PID=/var/log/tomcat/catalina.pid

You can also specify other environments Vars applied for you there

Note: by default, they do not create this file Otherwise it will be overwritten on update

Updated for comments:

The problem is that if you use sudo, / etc / profile

You can test it like this:

# Write a variable SMALLTEST into the profile file
sudo su -c "echo \"export SMALLTEST=Hello World\" >> /etc/profile"

# create a small script (like your startup.sh) that read the variable
echo "echo Variable is set to: \$SMALLTEST" > smalletst
chmod  +x smalletst 

# Execute the script with sudo
sudo ./smalletst 
Variable is set to:

You see env VaR is not set

Update 2:

If you want Tomcat to run as a service, you should look at / opt / Tomcat / bin / daemon SH script You can put Ti / etc / init D / Tomcat and specify your environment In setenv SH medium

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>