I am a newbie to Ubuntu 12.10 and moved to it from Windows.
In Windows I have configured the environment variable to include servlet-api.jar in the CLASSPATH variable so I do not have to type -cp <path to servlet-api.jar> every time I compile.
For normal Java programs, I have set the JAVA_HOME using:
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386" >> ~/.bashrc
With that solved, I need to set the CLASSPATH but do not know how to.
Please help on that!
Also I read on some forums that I should change the CLASSPATH manually each time I compile because changing the CLASSPATH may upset other applications.
Next, I tried this command to start Tomcat
service tomcat7 start but I got an error :
You need root privileges to run this script I do not know why. Help me solve that!
And if within the scope, please tell me how the directory structure of tomcat in Windows differs from that in Ubuntu.
Misc
I used sudo apt-get install tomcat7 to get Tomcat 7.
You don't say whether you're using an Ubuntu Tomcat package or a standalone Tomcat installation.
For a standalone Tomcat, you will be starting and stopping it using the scripts in its bin directory: startup.sh and shutdown.sh. In that case, Tomcat will use the environment variable values set at the time of invocation.
When doing this, you can set the environment variables prior to running these commands.
The same is true for the Tomcat 6 or Tomcat 7 that Ubuntu distributes as packages.
These neatly separate the $CATALINA_HOME directory (where the Tomcat 7 distribution is supposed to be) from the $CATALINA_BASE directory (where all of the changes and additions for a particular Tomcat instance are supposed to be. For the tomcat7 package, the first directory is /usr/share/tomcat7, while the second is /var/lib/tomcat7.
You can find startup.sh and shutdown.sh in /usr/share/tomcat7/bin and of course you can use them.
However, if you use the Tomcat provided with Ubuntu, you're probably going to want to run it just like any other standard system service, and the packages support this: e.g. in the case of tomcat7, you can just use
sudo service tomcat7 status
sudo service tomcat7 start
sudo service tomcat7 stop
sudo service tomcat7 restart
just like you can for any system service, and it uses the same mechanism as other system services do:
the shell script /etc/init.d/tomcat7 is used to start and stop Tomcat 7
/etc/default/tomcat7 is its configuration file, allowing a few parameters to be set
Using this method, you cannot specify additional environment variables for Tomcat to use by setting them in your shell or in /etc/default/tomcat7; they will not be passed to Tomcat.
However, there is a second method to set environment variables: if you set them in the shell script /var/lib/tomcat7/bin/setenv.sh (or, if you must, /usr/share/tomcat7/bin/setenv.sh), they will be picked up and passed to Tomcat. This method always works.
Finally, Tomcat offers finer control than just using a $CLASSPATH when it comes to specifying additional classes or JARs to be loaded on startup: in its conf/catalina.properties configuration file, you can set the common.loader, server.loader and shared.loader to a list of directories and/or JAR files to be loaded in additional to the standard ones.
All it means is that you should do that as a superuser - which translates to administrator in windows so you should try something like sudo service tomcat7 start
Try export CLASSPATH=/usr/share/tomcat7/lib/servlet-api.jar:/usr/share/tomcat7/lib/jsp-api.jar - This will depend on where your tomcat installation in located.
You can get more here
Cheers
Related
Here's what I do in SpringBoot on Windows to read an environment variable (location of log folder).
In Windows Server, I set a System environment variable for "LOG_HOME" with the value with the directory that SpringBoot should use to write logs.
In SpringBoot's application.properties, I have:
logging.file.name= ${LOG_HOME}/ws.log
Works great!
But in Ubuntu Linux 20.04, the same approach doesn't work for me at all.
When the WAR file tries to deploy on Ubuntu 20.04 using this similar technique:
(in .bashrc): export LOG_HOME = /home/ubuntu/logs
reboot (to reload the environment for sure)
I get this error in the Tomcat log when trying to deploy the WAR file:
java.lang.IllegalArgumentException: Could not resolve placeholder 'LOG_HOME' in value "${LOG_HOME}/ws.log"
So, it seems that Spring doesn't see the environment variable set in Ubuntu.
I wrote a simple Java program just to check the value of the environment variables and they were all created as expected including the LOG_HOME as shown in Linux "printenv".
If possible, I need a technique that will work on Ubuntu without changing the working SpringBoot implementation on Windows Server.
Thanks in advance for suggestions.
Instead of exporting in shell session like
export LOG_HOME = /home/ubuntu/logs
try this as -D VM argument in your starup command
eg:
java -cp=xxx mainclass -DLOG_HOME=/home/ubuntu/log
if you are using tomcat then :
VM args can be added catalina.sh file under CATALINA_OPTS.
For tomcat, add your environment variables to $TOMCAT_HOME/bin/setenv.sh where $TOMCAT_HOME is the directory of your tomcat installation.
The solution for me posted by the extremely helpful satyesht above, was to edit the Catalina.sh file and add the "-D" name-value pair option under CATALINA_OPTS. Thanks to all who posted. :)
I have a problem. i have 3 tomcat directories in my windows 8 system :
D:/apache tomcat 6/
D:/apache tomcat 6_old/
D:/tomcat6/
The last two folders are old and dirty. I want to use fresh first one; so I am trying to run it.
D:/apache tomcat 6/bin/tomcat6.exe
But strangely windows runs tomcat with configuration and webapps in third one (D:/tomcat6/).
I have set CATALINA_HOME in environment variable; but no effect.
Can you please help. Thanks.
Setting CATALINA_HOME helps, but you have to use startup.bat to start Tomcat, not the tomcat6.exe
You can also do this with a small batch file (I use it that way since I have a lot of tomcat installations on my computer. Here is one of my scripts:
setlocal
cd C:\mock\apache-tomcat-7.0.27\bin
set CATALINA_HOME=C:\mock\apache-tomcat-7.0.27
call startup.bat
Don't see any reason why starting first tomcat starts a different one.
You can remove unused tomcat directories, so that you just have single Tomcat. Also make sure to kill all java/tomcat processes and then start the required one.
Change your CATALINA_HOME
from
D:/tomcat6/
to
D:/apache tomcat 6/
also make sure the following is added to path variable
%CATALINA_HOME%\bin;
I have a maven project, after running command mvn install all project as well as module compile and copied to local repository successfully. But now I want to run the generated web application in tomcat6. Client provided some parameter for tomcat like -Dapp.username,-Dapp.username, which will be used internally once project will start.ButI do not know how to set these additional parameter in tomcat6. Below is my development environment
OS = Windows
Tomcat = tomcat 6.0.27
Please help me?
For Tomcat 6 you should add the params to the startup.sh (Windows startup.bat). For Tomcat 7 and above you should set the parameters in the {Catalina Root}/bin/setenv.sh like such:
export CATALINA_OPTS="$CATALINA_OPTS -Dapp.username=username -Dapp.password=password"
Or in Windows:
set CATALINA_OPTS="$CATALINA_OPTS -Dapp.username=username -Dapp.password=password"
NOTE: Notice the $CATALINA_OPTS at the beginning so you don't wipe out any previously set values. Not doing so can create a very hard to debug problem!
If the parameters you are setting are solely to be used by Tomcat then be sure to set it using CATALINA_OPTS.
If your application will be using the parameters then be sure to use JAVA_OPTS instead. Tomcat will also read these parameters. This can also go in the setenv.sh file. For instance:
export JAVA_OPTS="$JAVA_OPTS -Dapp.username=username -Dapp.password=password"
Or in Windows:
set JAVA_OPTS="$JAVA_OPTS -Dapp.username=username -Dapp.password=password"
You can set an environment variable to do that. E.g. in Linux:
export JAVA_OPTS="-Dapp.username -Dapp.username"
Or in Windows:
set JAVA_OPTS="-Dapp.username -Dapp.username"
Do this before starting Tomcat
You will want to set the CATALINA_OPTS system variable - this is read by Tomcat (and only by Tomcat) when starting. As #Betoverse says you can set this using the two methods:
export CATALINA_OPTS="-Dapp.username -Dapp.username"
Or in Windows:
set CATALINA_OPTS="-Dapp.username -Dapp.username"
You can add that command to your ~/.profile on UNIX to have it set automatically.
I have tested params for Tomcat 7/8 on Windows 10 and CentOs 7 (Linux).
1) On Windows need to create setenv.bat in the {TOMCAT_HOME}/bin/ path and insert there such code:
set CATALINA_OPTS=-Dapp.username=admin -Dapp.password=12345
IMPORTANT: do not use quotes (" ") for setting params on windows.
2) On CentOs need to create setenv.sh in the {TOMCAT_HOME}/bin/ path and insert there such code:
export CATALINA_OPTS="-Dapp.username=admin -Dapp.password=12345"
You can also create {TOMCAT_HOME}/conf/conf.d/custom.conf and insert the same export command there.
If you don't want to change your environments or edit the .sh files you can start the server with something like the following
CATALINA_OPTS="-Dparam1=value1 -Dparam2=value2" catalina.sh start
before starting tomcat server right click project --> Run as --> Run Configurations
second tab --> -Dname=values , -Dname=values , -Dname=values
what about +Dname=value ,, values it become encrypted
I have different projects using different version of JDK (5.0, 6.0) and Tomcat(6.0, 7.0), so how should my JAVA_HOME and CATALINA_HOME be set in environment variables?
Or maybe it is NOT necessary to set JAVA_HOME and CATALINA_HOME in environment variables if I am running my App by .War file? The jdk/tomcat server will be running the version I picked when I packed it (through Eclipse -> preferences...).
Inside the tomcat startup script /bin/catalina.sh, the following environmental variables are used:
JAVA_HOME is the path of JDK that used to run the tomcat and web applications
CATALINA_HOME is the path of the tomcat binaries files
CATALINA_BASE is the path the tomcat configuration files
So , how about this approach? For example :
Install JDK 5.0 to : /opt/jdk5
Install JDK 6.0 to : /opt/jdk6
Install tomcat 6.0 to :/opt/tomcat6
Install tomcat 7.0 to : /opt/tomcat7
Each of your web application has their own folder to hold their own tomcat 's configuration. For example :
/home/web1 for the web application 1
/home/web2 for the web application 2
Inside each of these folders , we need the following sub directories: conf, logs, temp, webapps, and work.Simply copy these sub directories from the tomcat installation folder (ie. /opt/tomcat7/) .Then put the .war to the corresponding webapps folders (e.g. /home/web1/webapps/webappl.war , /home/web2/webapps/webapp2.war ).
Finally , write a script to start the tomcat using different JDK and tomcat for each application . For example , to start web1, your script should look likes:
JAVA_HOME=/path/to/jdk #eg./opt/jdk6
CATALINA_HOME=/path/to/tomcat/installation #eg./opt/tomcat7
CATALINA_BASE=/home/web1/
export JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE
$CATALINA_HOME/bin/catalina.sh start
Reference :
http://www.mohancheema.net/appserver/setting-tomcat-to-run-mutiple-instances-of-it
If you are running it with in Eclipse, you can use the Run Configuration dialog to set any enviornment variables that you need to change. These get automatically set when you execute the specified Run configuration. To use this, Right Click on your project, select Run -> Run Configurations. In that you can select a Run Configuration, and goto the Environment tab, and there you can specify the custom variables you want, and also you can override anything that is set by the O/S.
If you want to do this outside eclipse, and you keep a copy of Tomcat dedicated for each project, edit the startup.sh or startup.bat files depending on your OS and then set the environemnt variables explicitly there.
Ex. For Project 1:, on top of /opt/apache-tomcat6-1/bin/startup.sh file add these lines
export JAVA_HOME='/opt/jdk1'
export JAVA_HOME='/opt/apache-tomcat6-1'
Ex. For Project 2:, on top of /opt/apache-tomcat6-2/bin/startup.sh file add these lines
export JAVA_HOME='/opt/jdk2'
export JAVA_HOME='/opt/apache-tomcat6-2'
If you don't have a dedicated copy of Tomcat, then you can create a shell script / batch file per project which will set the necessary environment variables like this and then invoke the corresponding startup.sh or startup.bat file.
These variables are used by the scripts that start Tomcat, and don't matter otherwise. You can set them immediately before running the startup.sh script, or you can edit the catalina.sh script to set the values in the script itself (this is a good way to do it, since catalina.sh is shared by the other scripts), or you can write your own scripts which set the variables and then call the tomcat scripts... There are many possibilities. You just can't set the variables globally.
I'm setting up my development environment for writing web applications using Java, and I'm in need of some help.
What I have done:
Installation of Java SE 6 from Sun
I installed (sudo apt-get install …) the following packages (one at a time as some of them requires user interaction) to get Java SE 6 from Sun: sun-java6-bin sun-java6-doc sun-java6-fonts sun-java6-javadb sun-java6-jdk sun-java6-jre sun-java6-plugin sun-java6-source .
I also set JAVA_HOME by adding JAVA_HOME=”/usr/lib/jvm/java-6-sun/” to /etc/environment.
Began installing and configuring Tomcat 5.5
I installed (sudo apt-get install …) the following packages: tomcat5.5 tomcat5.5-admin
What I have at the moment:
I'm able to connect to http://localhost:8180/admin and get the admin web application which I installed by installing the tomcat5.5-admin package. The Tomcat server is running as a deamon.
My problems and questions:
The environment variable $CATALINA_HOME doesn't seem to be defined. How should I define it? (The same way as my $JAVA_HOME maybe? But if so, which path should I assign it?)
To deploy a war, can I just copy the JAR to $CATALINA_HOME/webapps? Or do I need to change the file permissions on the war? (Here I assume $CATALINA_HOME is set correctly.)
What's the user and password I need for the admin web application I installed? How do I change them?
Are there any best practices for Tomcat 5.5 on Ubuntu which I should think of?
You have to add it manually. You can either do it in the file:
~/.bashrc <---- for session-wide variables
/etc/environment <---- for system-wide variables
You should set CATALINA_HOME in here by adding the following line:
CATALINA_HOME=PATH_TO_WHERE_YOU_ARE_RUNNING_TOMCAT
Afterwards, if you edited .bashrc, reload the file, by typing in:
Source .bashrc
If it was /etc/environment, I believe you can do the same thing. If that doesn't work, try logging off then in. If that doesn't work, just restart.
The path where your Tomcat is installed. I don't know, I am on openSUSE, and usually install tomcat in my preferred directory, most likely under my /home/adeel/. You can check it using whereis tomcat command on your console, or may be try whereis catalina. It might give you the path of your tomcat. This time I am running tomcat under my Netbeans, just for a try, and didn't set the environment variable.
You may just copy the war file under the CATALINA_HOME/webapps/ directory. Or you can even place it exploded. I don't think you would need to change the privileges of your war.
You can set it in CATALINA_HOME/webapps/tomcat-users.xml. Below is the example,
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="tomcat"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager"/>
</tomcat-users>
Not really. The only suggestion I have in my mind at the moment is, to set it as user-variable, not in system-variable.
NOTE: In case you are using Tomcat under Netbeans, number of tomcat configuration is provided within the IDE, for example, you can change the port, username/password, VM options, etc. Beware Netbeans keep its own place and file for web-app deployment in Tomcat, and doesn't use CATALINA_HOME/webapps/.
You could do an "echo $CATALINA_HOME" to check if it has been defined or not.
It should be set to the installation directory of tomcat. Mine is set to /usr/local/tomcat
Are you using an IDE? I was able to provide a user name and password for admin when adding Tomcat as a server in NetBeans. You need to set the Catalina_Home first.
I had some trouble installing Tomcat on Ubuntu (through sudo apt-get install and synaptic manager) with NetBeans. The best option is to download the tar file (using wget) and extract it to your choice of path.