Tomcat 7 setenv.sh is not found - java

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.

Documentation does mention about the absence of setenv.(sh|bat) file:
(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\jre6"
exit /b 0
On *nix, $CATALINA_BASE/bin/setenv.sh:
JRE_HOME=/usr/java/latest
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt

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.

If you don't find the "setenv.sh" or "setenv.bat" in bin folder of tomcat, follow the following setps:
Create new file in bin folder of tomcat.
Rename it to setenv.sh for linux user or setenv.bat for windows user
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.

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.

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

Related

How to upgrade JDK from Oracle to Zulu in redhat linux

I want to upgrade my Linux JDK from Oracle to Azul-Zulu.can someone helps me to do this.
What to do after downloading the tar.gz Zulu package?
I see that after extracting the downloaded package we need to put it in the path where we need to access java. Is that correct or what we can do more like setting environment variables etc.
the answer to your question depends on what you actually want to start with the JDK. Sometimes is is sufficient to change the path to java binary in a start script, e.g. Eclipse or Tomcat, sometimes you also need to setup the variable JAVA_HOME.
To setup the java for yourself only:
Check your shell by running echo $SHELL
-> /bin/bash
-> /bin/zsh
-> /bin/tcsh
or something like that Locate your shell's config file:
bash: ~/.bashrc
zsh: ~/.zshrc
tcsh: ~/.cshrc or ~/.tcshrc
and optionally most of the shells: ~/.profile or ~/.login check those file(s) if you already have variable declarations for: JAVA_HOME JRE_HOME (and rarely seen) SDK_HOME JDK_HOME
check whether any of those files contain a setup for the variable PATH (probably has)
If you found any of the *_HOME variables from above you can change them to reflect your new java home directory: e.g. zulu11.37.17-ca-jdk11.0.6-linux_x64 located under /opt/zulu11.37.17-ca-jdk11.0.6-linux_x64 would mean to set the variables as follows: zsh and bash:
export JAVA_HOME=/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
export JRE_HOME=/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
tcsh
setenv JAVA_HOME /opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
setenv JRE_HOME /opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
SDK_HOME and JDK_HOME may point to the above locations as well but are normally unused.
If you located your PATH somewhere it may read something like this: zsh and bash:
export PATH=~/bin:$PATH
tcsh:
setenv PATH ~/bin:$PATH
In order for your new java to appear "before" the "other" java you need to update (or create if missing) this to e.g.: zsh and bash:
export PATH=~/bin:/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64/bin:$PATH
tcsh:
setenv PATH ~/bin:/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64/bin:$PATH
After completely logging out and in again your JAVA_HOME and PATH can be controlled in a shell like this:
echo $JAVA_HOME -> should point to *your* java folder
echo $PATH -> should contain *your* java folder's bin directroy
which java -> should list the new java binary instead of /bin/java or /usr/bin/java
BTW: the variables JAVA_HOME, JRE_HOME and PATH may also be set in a startscript, e.g. catalina.sh for tomcat or the eclipse.ini for eclipse if you do not want to modify your environment.
If you download the RPM/DEB instead of the tar.gz and install the package you (may) not need configure anything since the packages might re-configure your system for you
Cheers, Holger

Tomcat 6 JAVA_HOME

I try to set the JAVA_HOME path as my Tomcat server is looking for it. I am trying to set it but it doesn't seem to work and causes an error when I do. I am trying to set the JAVA in the setclasspath.bat using
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
This is at the start of the setclasspath.bat
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo At least one of these environment variable is needed to run this program
goto exit
When I set this and run "startup.bat start" it displays
Files was unexpected at this time
Can you help me?
Note: I realise this is already quite an old question, but many of the answers posted here are either incomplete or inaccurate.. Hopefully this will help save a few headaches.
Firstly: Tomcat does not need a JDK to run, it will work just fine with a JRE, as long as it knows it's a JRE.
Secondly, the error from the original question is coming from an issue with syntax of the set JAVA_HOME=... command. Apache themselves could handle it better with stripping and adding " quote marks.
Also, I would highly recommend creating a setenv.bat file in the bin folder. It's absent by default, so if you don't already have one, create it and add your set JAVA_HOME=... or set JRE_HOME=... lines there.
Run with JRE
As per running.txt:
The JRE_HOME variable is used to specify location of a JRE. The
JAVA_HOME variable is used to specify location of a JDK.
Using JAVA_HOME provides access to certain additional startup options
that are not allowed when JRE_HOME is used.
If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.
So, to startup this way, you'll need the following:
set "JAVA_HOME="
set "JRE_HOME=C:\Program Files (x86)\Java\jre7"
Clearing the JAVA_HOME variable is a failsafe, but it's not really required. As per the docs, Tomcat will try use the JRE variable first anyway.
Solution for Issue in Question
Take special note the position of the quotation marks. This way keep the entire string together in one variable, without including the quotation marks in the variable content itself.
For example:
set %TEST%="hello"
echo "%TEST%"
Will output ""hello"".
set "%TEST%=hello"
echo "%TEST%"
Will output "hello".
So, the startup batch file script was trying to use ""C:\Program Files (x86)\Java\jre7"", in which the first non-escaped space is between "Program" and "Files".
As already pointed out, removing the quotation marks (in this particular case at least) would work, but it's dangerous to rely on that. Rather play it safe from the start and wrap the variable name and value in quotation marks.
I had the same problem on Windows 7 with the following definition (I put it in a setenv.bat file in the jdk bin folder as specified by tomcat 7's RUNNING.txt.
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
I just tried removing the double quotes altogether:
set JAVA_HOME=C:\Program Files (x86)\Java\jre7
And tomcat then started.
First, install java and locate the instalation path.
Locate the tomcat installation path and find the startup.bat in \bin
Open startup.bat and add below(example) lines just after setlocal and before rem Guess CATALINA_HOME if not defined
:: JAVA
set JAVA_HOME=D:\thushara_data\Java\jdk1.8.0_73
set PATH=%JAVA_HOME%\bin;%PATH%
Now try to re-run startup.bat
Place the path in quotes:
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
The error is due to the fact that it's parsing the Files in Program Files as a separate parameter, which SET doesn't expect. Why SET isn't reading it properly I can't say without knowing more about what OS you're using, what command shell you're running Tomcat from, and so on.
If not able to set the variables manually:
to set JAVA_HOME and JRE_HOME
go to advance system setting and click on environment variables
under system variables click
new variable name : JAVA_HOME
variable value : [path of jdk]C:\Program Files\Java\jdk1.8.0_181 and click ok
similarly add JRE_HOME
click new variable name : JRE_HOME
variable value : [path of jre]C:\Program Files\Java\jre1.8.0_181
click Ok > Ok > Ok
You are pointing to a JRE. You need to point to a JDK, which given the location of your JRE might be something like C:\Program Files (x86)\Java\jdk1.6.0_26 or similar. Or, if you only have a JRE installed, you'll need to install a full JDK. Tomcat needs to be able to compile JSPs into .class files, which a JRE can't do.
The reason why your command failed is because it has white spaces between 'Program Files (x86)' and so it starts reading the command from 'Files (x86)'. So instead we put it in between double quotes such as the following.
try this..
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"
Try
https://askubuntu.com/questions/446294/how-to-start-tomcat7-when-catalina-sh-does-not-work
It can give you some insight even though it's not Windows it still looks for those shell scripts except their extensions in Window is .bat not .sh
You Can Also Try This For jre1.8v:
Open cmd In Tomcat Server Folder And Enter Command
set "JAVA_HOME=C:\Program Files (x86)\Java\jre1.8.0_45"
Then Enter Command cd bin
Then To Start Tomcat Server Enter Command startup
To Stop Tomcat Server Enter Command shutdown
If It Fails To Start Although You Can Run Command: cd startup.bat

In which file Tomcat Java Memory options are saved

I want to change memory configuration of Tomcat. I know it can be done at
Start > Apache Tomcat > Configure Tomcat > Java Tab] as can be seen below
and specifying options like
-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m
-XX:MaxHeapFreeRatio=70
there.
However this program group is created if I install Tomcat from an executable. I have installed Tomcat by simply extracting the zip which does not create Program group. So now where can I specify this information
With regards to the question of where Tomcat's memory options are saved when using the service version, on my machine at least they can be found in the Windows Registry at:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat-6\Parameters\Java
Initial memory and Maximum memory are recorded against the JvmMs and JvmMx values, while the options text is recorded against the Options value.
The Tomcat-6 portion of the address on mine is, I believe, based on the identifier I gave to the service (i.e. within the service manager Tomcat is named "Apache Tomcat 6.0 Tomcat-6"), and you may not need to go through Wow6432Node depending on whether you're using 32-bit or 64-bit Tomcat.
I'm assuming here that they haven't made any dramatic changes in where this information is stored in versions of Tomcat more recent than Tomcat 6.
Ohkay while digging inside Tomcat I found some information in one of its txt files (point 3.4) and online:
Apart from CATALINA_HOME (which is set to apache-tomcat-x.x.x directory, for e.g. C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.41) and CATALINA_BASE (optional, defaults to CATALINA_HOME), 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\jre6"
exit /b 0
On *nix, $CATALINA_BASE/bin/setenv.sh:
JRE_HOME=/usr/java/latest
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
To set Java options for memory allocation for web app, add something like following (as per memory requirements of your application) to the same file
set JAVA_OPTS="-Xms256m -Xmx512m"
The CATALINA_HOME and CATALINA_BASE variables cannot be configured in the
setenv script, because they are used to locate that file.
All the environment variables described here and the setenv script are
used only if you use the standard scripts to launch Tomcat. For example, if
you have installed Tomcat as a service on Windows, the service wrapper
launches Java directly and does not use the script files.

WAR file is giving me out of memory error

I am using tomcat 6 and the WAR file I have deployed is giving me out of memory error. I have installed tomcat6 using windows installer because of it I am unable to find any catalina.bat in tomcat6.0\bin folder where I can configure CATALINA_OPTS variable.
If you are not able to find the catalina.bat then edit your tomcat6w.exe and add
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled
-XX:+UseConcMarkSweepGC
-XX:PermSize=128m
-XX:MaxPermSize=512m
You should change the “Xms” and “PermSize” value base on your server
capability.
Once done with editing simply Restart Tomcat.
Hope it helps!
If you have trouble setting CATALINA_OPTS in tomcat installation, you can set it as a environment variable in windows.
UPDATE:
If the previous method is not working then you can create a file, setenv.bat in bin directory of tomcat.
And in that file you can put the arguments like:
set CATALINA_OPTS= "JVM Conditions here"
This did the trick for me, try it out.
Few links for your reference:
http://www.oracle-base.com/articles/misc/apache-tomcat-7-installation-on-windows.php
How to tune Tomcat 5.5 JVM Memory settings without using the configuration program

Set environment variable in shell script/access in Tomcat Application

I want to add and environment variable which can access by my tomcat web-app. I have gone through this link but i want to set environment variable in root user. How to do that?
According to the docs (http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt) you should set all env vars in $CATALINA_HOME/bin/setenv.sh
EDIT:
For completeness, I guess it's worth mentioning that even though this is the recommended way, the docs above state that:
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.
In case it is absent, you might also want to look for env vars in:
/etc/tomcat/tomcat[67].conf (suse) or
/etc/default/tomcat[67].conf (e.g. ubuntu) or
/etc/sysconfig/tomcat[67].conf (rhel, fedora)
This is how you can do it
sudo su and cd to /var/lib/tomcat8/bin/ (or whichever is your tomcat bin path)
touch setenv.sh(if it doesn't exist), if file present already do 'vi setenv.sh'
chmod 777 setenv.sh (make file executable)
vi setenv.sh and set following line in setenv.sh
export key=value
sudo systemctl restart tomcat.service
In your java file you can use the following code to check if the variable is set
private static void printEnv() {
System.out.println("******************************Environment Vars*****************************");
Map<String, String> enviorntmentVars = System.getenv();
enviorntmentVars.entrySet().forEach(System.out::println);
System.out.println("******************************system Vars*****************************");
Properties enviorntmentProperties = System.getProperties();
enviorntmentVars.entrySet().forEach(System.out::println);
}
got the solution...what i have done is i have put the export statements in /etc/init.d/tomcat6 at top and restarted the server by command sudo /etc/init.d/tomcat6 restart. So now my web-app running in tomcat server can access that variable.
Doesnt this work?
Go to your environment file.
sudo vi /etc/environment and
Add the required variable. and save the file.
I think in the recent Ubuntu, You would have to restart your system for the changes to take effect.

Categories

Resources