Tomcat 7 setenv.sh is not found
Asked Answered
L

5

27

I downloaded and extracted the apache-tomcat-7.0. As per the instructions in the RUNNING.txt (%CATALINA_BASE%/RUNNING.txt), it should set the JRE_HOME in the "setenv.sh" file.

Where is this file located ? Documentation said, it would be in CATALINA_HOME/bin directory. However this file is not present there.

Lovmilla answered 28/2, 2012 at 10:25 Comment(0)
A
31

Documentation actually mentions the absence of the setenv.(sh|bat) file (by default):

(3.4) Using the "setenv" script (optional, recommended)

Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can be specified in the "setenv" script. The script is placed either into CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be readable.

By default the setenv script file is absent. If the script file is present both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is preferred.

For example, to configure the JRE_HOME and CATALINA_PID variables you can create the following script file:

On Windows, %CATALINA_BASE%\bin\setenv.bat:

  set "JRE_HOME=%ProgramFiles%\Java\jre@MIN_JAVA_VERSION@"
  exit /b 0

On *nix, $CATALINA_BASE/bin/setenv.sh:

  JRE_HOME=/usr/java/latest
  CATALINA_PID="/run/tomcat.pid"

https://github.com/apache/tomcat/blob/10.1.9/RUNNING.txt#L151

Antimonic answered 21/9, 2013 at 18:54 Comment(0)
O
13

Just create one yourself; it isn't part of the distribution. It's not that hard. For your case, simply add

JRE_HOME=/path/to/your/java/installation

to the file and make it executable (chmod 755 setenv.sh).

You can also add other options (e.g. -Xmx) if necessary.

Outdate answered 28/2, 2012 at 10:30 Comment(2)
shouldn't it be export JRE_HOME=... ?Boutique
Ghm, I use a similar command for CATALINA_OPTS and it works without exporting. In any way OP can confirm this.Outdate
S
7

If you don't find the "setenv.sh" or "setenv.bat" in bin folder of tomcat, follow the following setps:

  1. Create new file in bin folder of tomcat.
  2. Rename it to setenv.sh for linux user or setenv.bat for windows user
  3. Now you can set multiple thing into this file:

Setting JRE_HOME

For linux user

JRE_HOME=/path/to/jre/jre6

For Windows user

set JAVA_HOME=C:\Path\to\jre\jdk6

Setting JAVA_OPTS

For linux user

JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx512m -DFOOBAR_CONFIGURATION_FILE=file:///C:/foobar.properties"

For windows user

set "JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx512m -DFOOBAR_CONFIGURATION_FILE=file:///D:\foobar.properties"

Restart tomcat after setting variables. That's it.

Sundin answered 27/3, 2017 at 16:4 Comment(2)
Great!! Worked for meLactose
These options usually goes in the CATALINA_OPTS though as JAVA_OPTS is used by the internal Tomcat commands too: stop process, the version command etc.Cygnus
D
1

User Mindas' answer is completely correct: it is necessary to create the setenv.sh file in either the CATALINA_HOME or CATALINA_BASE directory, as the comment in the catalina.sh file indicates.

However, there is a "chicken and egg" problem wherein Tomcat must guess the location of the CATALINA_HOME/bin/ directory in the case where the CATALINA_HOME environment variable is not set.

I have encountered this situation on a Ubuntu server where fortunately Tomcat guesses the CATALINA_HOME/bin/ directory correctly. For a single-user environment where customization of Tomcat for different users isn't necessary, it seems that setting the JAVA_HOME or JRE_HOME environment variable in the catalina.sh script would be a solution to the "chicken and egg" problem.

Dibs answered 20/9, 2013 at 23:33 Comment(0)
T
0

In my case, I downloaded Tomcat for Windows. It also came with Linux shell scripts, so I created a 'setenv.sh' and tried to run it from Windows Subsystem for Linux, but got the above error. The issue was that the non-binary shell scripts were formatted for Windows, and Linux didn't know how to run them. After converting them to Linux format, it was able to recognize and run the scripts. Try this to convert from Windows to Linux:

dos2unix $CATALINA_HOME/bin/*.sh
Tibbitts answered 30/12, 2022 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.