Finally found the right configuration file my self. It is /etc/default/tomcat. There I was able to set

JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64

and it works now.

Thanks for the help.

Answer from André Stannek on Stack Exchange
🌐
DZone
dzone.com › coding › java › how to set up jdk and tomcat on ubuntu
How to Set Up JDK and Tomcat on Ubuntu
December 29, 2017 - Step 1: Download the latest JDK and Tomcat (in this article, I am using JDK 9 and Tomcat 9). Step 2: Change the permissions and ownership of the "opt" directory.
🌐
CodeJava
codejava.net › servers › tomcat › 4-ways-to-change-jre-for-tomcat
4 Ways to Change JRE for Tomcat
August 5, 2019 - In this article, we summarize different ways to change JRE for a Tomcat installation.To know which JRE version is used for Tomcat, go to the following URL: localhost:8080/manager/statusAnd look at the JVM Version column: This way is very simple to implement but it works only for Tomcat installed from a zip distribution (in contrast to Tomcat installed as a service). If only the JAVA...
🌐
PTC
support.ptc.com › help › thingworx_hc › thingworx_8_hc › en › ThingWorx › Help › Installation › Installation › install_java_and_apache_tomcat__ubuntu_.html
Install Java and Apache Tomcat (Ubuntu)
September 29, 2016 - $ sudo mkdir -p /usr/share/tomcat8.5 $ sudo mv apache-tomcat-8.5.xx /usr/share/tomcat8.5/8.5.xx $ sudo addgroup --system tomcat8.5 --quiet -force-badname $ sudo adduser --system --home /usr/share/tomcat8.5/ --no-create-home --ingroup tomcat8.5 --disabled-password --force-badname --shell /bin/false tomcat8.5 $ sudo chown -R tomcat8.5:tomcat8.5 /usr/share/tomcat8.5 · 17. Define environment variables in /etc/environment: $ export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_xxx $ export CATALINA_HOME=/usr/share/tomcat8.5/8.5.xx
Find elsewhere
🌐
ComputingForGeeks
computingforgeeks.com › home › switch default java version on ubuntu / debian
Switch Default Java Version on Ubuntu / Debian [Guide]
March 25, 2026 - Some applications (Tomcat, Maven, Gradle, Elasticsearch) read JAVA_HOME instead of using whatever /usr/bin/java points to. You can set this per-session, per-user, or system-wide without touching alternatives at all. export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 $JAVA_HOME/bin/java -version
🌐
Coderanch
coderanch.com › t › 110843 › os › update-Tomcat-JVM-Linux
How to update Tomcat's JVM in Linux? (GNU/Linux forum at Coderanch)
Thus, when tomcat loaded it referred to the old JVM. Changing this variable to /usr/java1.5.0_08 fixed the problem. Thanks again for your reply.
🌐
Medium
medium.com › @dev_padawan › how-to-setup-apache-tomcat-9-on-ubuntu-the-easy-way-5dc434113797
How to setup Apache TomCat 9 on Ubuntu the easy way | by Robin | Medium
April 13, 2020 - You must have java installed on your machine for Apache TomCat to work. The supported java version at the time of writing for TomCat 9 is java 8 and above.
🌐
Coderanch
coderanch.com › t › 735119 › application-servers › Changing-Tomcat-Service-JDK
Changing Tomcat Service JDK (Tomcat forum at Coderanch)
Hi...for future reference, I copied Tomcat9w.exe and renamed the copy Tomcat99w.exe, to match the service name, and I was able to change the JVM. The service exe file name has to match the Windows service name. Thank you. ... Boost this thread! ... Cant deploy through manager on tomcat 7.0.55 through iis 8.5 with ajp connector setup. 404 · String class can't find split method: wrong java version?
🌐
Coderanch
coderanch.com › t › 743772 › application-servers › java-version-web-app
Different java version for each web app (Tomcat forum at Coderanch)
June 29, 2021 - Seems like you're asking how to configure the listening port for an instance of Tomcat. Here's one of the tutorials I found online which tell you that: Modify the default Apache Tomcat port. And you also want to know how to specify the Java version it uses? 4 Ways to Change JRE for Tomcat.
🌐
JetBrains
jetbrains.com › guide › java › tutorials › migrating-javax-jakarta › update-tomcat-version
Updating Tomcat version - JetBrains Guide
November 12, 2024 - FROM tomcat:9-jdk17 ADD target/MyWebApp.war /usr/local/tomcat/webapps/MyWebApp.war EXPOSE 8080 CMD ["catalina.sh", "run"]
Top answer
1 of 5
34

There is a help text in catalina.sh. I will quote it here:

#   Do not set the variables in this script. Instead put them into a script
#   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#                   Required to run the with the "debug" argument.

# Ensure that any user defined CLASSPATH variables are not used on startup,
# but allow them to be specified in setenv.sh, in rare case when it is needed.
CLASSPATH=

if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
  . "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
  . "$CATALINA_HOME/bin/setenv.sh"
fi

When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE.

So the better way to set JAVA_HOME for the tomcat is:

  1. Create a script named setenv.sh in the folder CATALINA_BASE/bin, if it does not exist already.
  2. Add this line to setenv.sh

    export JAVA_HOME=/opt/java/jdk1.8.0_05
    
  3. Make it executable.


Why you should use this solution:

Setting environment variable in script is safer. Always try to set variables as locally as possible. Try do not use /etc/environment, /etc/profile and others if you really do not need Global Environment Variable. Setting JAVA_HOME in setenv.sh gives you ability to use different tomcats with different applications that need different version of java, but running by one user. Other user environment would not be affected by you.

2 of 5
6

Since you have set the environment variable for your own user and not for the superuser, you have two options:

  1. You will have to export the variable using -E option as follows:

    sudo -E /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh
    

    Note that this will export all environment variables while running the command. This is not preferred since the normal users environment is spilled out when you run the command as root. This is not desirable.

  2. Export the variable in root's .bashrc /etc/enviroment file. Open a terminal and type:

    sudo nano /etc/environment
    

    and enter your administrative password, and add the following lines to the end of the file:

    JAVA_HOME=/opt/java/jdk1.8.0_05
    PATH=$PATH:$JAVA_HOME/bin
    

    and then

    source /etc/environment
    

    or restart your machine and then retry the command you were using.


Update:

This answer provided hints as two why step 2 wouldn't work, sudo would reset the environment and provide a secure path, so all global variables are reset. A workaround would be to use

sudo su

and then execute command which uses the set environment variables.

🌐
Dotlinux
dotlinux.net › blog › how-to-install-and-switch-java-versions-on-ubuntu-linux
How to Install and Switch Java Versions on Ubuntu Linux
Select the same version as java to avoid compatibility issues. Many applications (e.g., Maven, Tomcat) require the JAVA_HOME environment variable to locate the Java installation.