Tomcat

Links

 * Website
 * Download

Startup and Shutdown
To startup the tomcat server use the follow command:

$ /opt/www/tomcat/bin/startup.sh

You can put this line into the file to start tomcat automatically when the system reboots.

To shutdown the tomcat server use the follow command:

$ /opt/www/tomcat/bin/shutdown.sh

Additionaly edit the file and put the command there. It will stop the tomcat server when the system shutdown.

Connecting Tomcat to Apache
The following links have more information about this topic:


 * The Apache Tomcat Connector
 * Apache configuration
 * Apache and Tomcat - How to

How to connect Tomcat to the popular open source web server, Apache ?


 * Download the mod_jk module]
 * Extract the files and go to the directory native.
 * Execute the following commands:

$ ./configure --with-apxs=/usr/local/apache2/bin/apxs $ make $ make install

Apache related parameters


 * --with-apxs[=FILE]
 * FILE is the location of the apxs tool. Default is finding apxs in PATH. It builds a shared Apache module. It detects automatically the Apache version (2.0 and 1.3).


 * --enable-jni
 * Build the jni_connect.so and the JNI worker.

Create the file. You can find more information about tomcat workers here.

ps=/ workers.tomcat_home=/opt/www/tomcat/ worker.list=worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.worker1.lbfactor=50 worker.worker1.cachesize=10 worker.worker1.cache_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.recycle_timeout=300
 * 1) Set the tomcat home
 * 1) Define 1 real worker using ajp13
 * 1) Set properties for worker1 (ajp13)

Edit the file and add these line at the end of the file:

JkWorkersFile /usr/local/apache2/conf/workers.properties JkLogFile    /usr/local/apache2/logs/mod_jk.log JkLogLevel   info JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkOptions    +ForwardKeySize +ForwardURICompat -ForwardDirectories JkRequestLogFormat    "%w %V %T" JkMount /examples/* worker1
 * 1) Where to find workers.properties
 * 1) Where to put jk logs
 * 2) Update this path to match your logs directory location (put mod_jk.log next to access_log)
 * 1) Set the jk log level [debug/error/info]
 * 1) Select the log format
 * 1) JkOptions indicate to send SSL KEY SIZE,
 * 1) JkRequestLogFormat set the request format
 * 1) Send everything for context /examples to worker named worker1 (ajp13)

You can mount more web application repeating the last command. Use the command JkMount for this. Example: JkMount /*.jsp worker2

Contexts
Source:

The Context element represents a web application, which is run within a particular virtual host. Each web application is based on a Web Application Archive (WAR) file

Normally, you configure the Context in the file or create a file in the directory  having the name of the Context.

Below you find a simple configuration of a Context that is located in a different directory than the default.

  

You can use other attributes to configure your Context. See the table below:

Loggers
Source:

An important consequence for Tomcat is that the  element found in previous versions to create a localhost_log is no longer a valid nested element of .

Tomcat has done away with localhost_log which you may be familiar with as the runtime exception/stack trace log. These types of error are usually thrown by uncaught exceptions, but are still valuable to the developer. They can now be found in the stdout log.

If you need to setup cross-context detailed logging from within Tomcat's code, then you can use a simple Log4J configuration. Note that this logging van be very verbose depending on the log level you chose to use. Note also that a Log4J logging configuration is not going to produce stack trace type logging: those stack traces are output to stdout as discussed above.

Follow the following steps to setup a file named that has internal Tomcat logging output to it:

log4j.rootLogger=debug, R log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=${catalina.home}/logs/tomcat.log log4j.appender.R.MaxFileSize=10MB log4j.appender.R.MaxBackupIndex=10 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n log4j.logger.org.apache.catalina=DEBUG, R
 * Create a file called with the following content and save it into.
 * Download Log4J (v1.2 or later) and place the in.
 * Download Commons Logging and place the (not commons-logging-api.jar) in  with the Log4J jar.
 * Start Tomcat

This Log4J configuration sets up a file called tomcat.log in your Tomcat logs folder with a maximum file size of 10MB and up to 10 backups. DEBUG level is specified which will result in the most verbose output from Tomcat.

You can (and should) be more picky about which packages to include in the logging. Tomcat uses defines loggers by Engine and Host names. For example, for a default Catalina localhost log, add this to the end of the above. Note that there are known issues with using this naming convention (with square brackets) in Log4J XML based configuration files, so we recommend you use a properties file as described until a future version of Log4J allows this convention. log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R log4j.logger.org.apache.catalina.core=DEBUG, R log4j.logger.org.apache.catalina.session=DEBUG, R

Be warned a level of DEBUG will produce megabytes of logging and slow startup of Tomcat. This level should be used sparingly when debugging of internal Tomcat operations is required.

Your web applications should certainly use their own Log4J configuration. This is valid with the above configuration. You would place a similar file in your web application's  folder, and log4jx.y.z.jar into. Then specify your package level logging. This is a basic setup of Log4J which does *not* require Commons-Logging, and you should consult the Log4J documentation for more options. This section is intended only as a bootstrapping guide.

Connecting Perl to Tomcat
Source:  (Author: Timothy Eden)

Here is a list of items for you to change in Tomcat to make Perl scripts work.


 * 1) Rename  to.
 * 2) Rename  to.
 * 3) Because we are going to use the examples Web app that comes with Tomcat, you need to add the subdirectory.
 * 4) The last item to change is the  file that is located at . Edit this file and uncomment the following lines of code (just remove the  to uncomment the code):

5. Change mapping for the cgi servlet inside the web.xml file. In this script, you need to uncomment the  by removing the. On to the Perl Script

With all the necessary files configured correctly it's time to create the Perl script (you are creating the Perl script but with a cgi extension). Type this script into a text editor, and save the file to : #!c:\Perl\bin\perl.exe print  "Content-type: text/plain\n\n"; foreach $var (  sort keys %ENV) { print "$var=\"$ENV{$var}\"\n"; } @values = split(/&/,$ENV{'QUERY_STRING'}); foreach $i (@values) { ($varname, $mydata) = split(/=/,$i); print "$varname = $mydata\n"; }

You need to now create an HTML file to execute the cgi script. Type this HTML code into a text editor, and save the file to :

  Environment Variables using GET    Press submit for a list of environment variables.  First Name:  Last Name:  </FORM> </BODY> </HTML>

You may notice that the first line of the Perl script is #!c:\Perl\bin\perl.exe. This path is the location of your Perl interpreter. If you are using the Unix or Linux platform, you may be used to seeing #!/usr/bin/perl as the first line.

To run the Perl script, begin by starting the Tomcat server. Go to the directory and run. If you are running Unix or Linux, run the script. If you need to stop Tomcat, then run the file. Once you have run you need to test to see if Tomcat is running. Open up a browser and type the URL http://localhost:8080 (the default port for Tomcat is 8080). If localhost does not work, then type http://127.0.0.1:8080.

To run the Perl script, type http://localhost:8080/examples/Test.html into your browser's URL address bar; you'll see the Web page you created above. Type your first and last name into the fields, and then click the Submit Query button to see the Web page that runs the Perl script. You can see the result of executing the Perl script.

Congratulations! You have run a Perl script from Tomcat. If you'd like more information on how to run Perl in Tomcat, you can go to the Apache Jakarta Project site. Click on the CGIServlet link to view the instructions on how to run a cgi script (which Perl is) in Tomcat.