jump to navigation

Apache mod_jk and tomcat with multiple virtual hosts November 22, 2008

Posted by maxmil in : Apache,tomcat , 14 comments

I recently had to configure a couple of different tomcat web applications as virtual hosts, each with its own domain. Although in my case tomcat is serving all the content of these applications i decided to use mod_jk to clean up the URL's and profit from apache's load balancing.

I found plenty of articles on the web that explained how to install and configure mod_jk with tomcat. However they all mapped an apache virtual host to a root tomcat context. Since i had two different tomcat context this seemed to mean that i would have to install two tomcat instances which was not a ideal solution.

The answer to my dilema was to define two separate hosts in tomcat, each one with its own mod_jk worker and one weapp as its root context. This idea came from Grig Gheorghiu. Thanks Grig!

I thought it would be worth describing the steps i took in a post so that others might benefit.

So here goes… My environment is:

Debian Lenny, Apache2.2, Tomcat 6.0.16.

http://test.domain1.org must map to webapp-domain1.war
http://test.domain2.org must map to webapp-domain2.war


Getting stdout from Tomcat 6 May 8, 2008

Posted by maxmil in : Java,tomcat , 2 comments

I am using tomcat version 6.0.14 and have been wrestling with its logging facilities. I use Log4J in my application which logs pretty much all i need to my designated log file.

However the other day i had a production error related to a hibernate query. When i turned on the hibernate show_sql property i expected the database queries to show up in the standard output of tomcat.

Since tomcat executes as a service there is no console in this version of tomcat and there is not stdout.log file in [tomcat install directory]/logs. The file used by tomcat is localhost_[datestamp].log, however my queries did not show up there either.

The solution was to add the swallowOutput attribute to my context definition with value “true”.

Avoiding jar locks with Tomcat 6 on Windows Server 2003 December 7, 2007

Posted by maxmil in : tomcat , 1 comment so far

I was having problems with a production tomcat 6 server on a Windows Server 2003 box.

If you update the war for a reloadable context while tomcat is running tomcat automatically tries to undeploy the current webapp and redeploy the new war.

On my Windows Server 2003 tomcat could not manage to undeploy the current application because the operating system had a lock on the jar files in WEB-INF/lib.

This left the application partially undeployed and broken.

The only solution was to stop the Tomcat service, manually delete the jar files and restart it which automatically redeploys the webapp.

The problem with this is that this is a production server with multiple webapps installed on it. I didn’t want to have to stop and start the server every time i needed to update just one of my webapps.

The solution has been to add antiJARLocking="true" to the context declaration in tomcat.

There is another option antiResourceLocking="true" which i have also added just to be on the safe side although i don’t think that in my case it’s necessary.

Sending parameters using GET method and UTF-8 October 25, 2007

Posted by maxmil in : tomcat , add a comment

In order to send parameters with GET using UTF-8 with tomcat you need to configure the connector

<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="8080" redirectPort="8443" URIEncoding="UTF-8"/>

Setting up apache web server and apache tomcat 5.5 with mod_jk October 22, 2007

Posted by maxmil in : Apache,Debian,tomcat , add a comment

To use tomcat for serving java and apache web server for serving other content you can use mod_jk. Here's a bried recap on how i have just configured them under debian.

1) Install both tomcat and apache.

2) Download binary mod_jk.so (from http://tomcat.apache.org/download-connectors.cgi)

3) Copy module to /usr/lib/apache2/modules/mod_jk.so

4) Create file /etc/apache2/mods-available/jk.load
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

5) Create file /etc/apache2/mods-available/jk.conf
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error

6) Create file /etc/apache2/workers.properties
# Tomcat and Java configuration #
# Definition for local worker using AJP 1.3 #

7) Create virtual host in /etc/apache/sites-available/myVirtualHost
ServerName max-p.sytec.tecfa.com
DocumentRoot /home/maxmil/project/tecfa-systec/webapp
ServerAdmin mpimm@tecfa.com
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/systec.log combined
Alias /edita "/home/maxmil/eclipse-tomcat/wtpwebapps/systec-edita"
<Directory "/home/maxmil/eclipse-tomcat/wtpwebapps/systec-edita">
Options Indexes +FollowSymLinks
JkMount /edita/* worker1
<Location "/edita/WEB-INF/">
deny from all

8) Enable new modules and site
cd /etc/apache2
ln -s mods-available/jk.load mods-enabled/jk.load
ln -s mods-available/jk.conf mods-enabled/jk.conf
ln -s sites-available/myVirtualHost sites-enabled/myVirtualHost

JNDI Oracle and Tomcat 5 July 5, 2006

Posted by maxmil in : Java,Oracle,tomcat , add a comment

Been having problems setting up a JNDI oracle datasource in tomcat 5. With apaches common-dbcp i was able to use the getConnection() method of java.sql.Datasource but the getConnection(String username, String password) method ALWAYS returns a java.lang.UnsupportedOperationException.

From what i have seen on the web this is a limitation of the apache common connection pool. However for Oracle there is another factory that is bundled within classes12.jar that you can use. I found the solution here…. http://www.microdeveloper.com/html/JNDI_Orcl_Tomcat.html

Basically its just a question of specifying the type of the datasource as oracle.jdbc.pool.OracleDataSource and the connection pool factory as oracle.jdbc.pool.OracleDataSourceFactory.

This is my context.xml

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="E:/work/proj/vaesa-st/bo/webroot" path="/soporte-tecnico/backoffice" reloadable="true" debug="1">
<Resource name="jdbc/SoporteTecnico_DataSource" auth="Container"
<ResourceParams name="jdbc/SoporteTecnico_DataSource">

and from my web.xml

<description>Soporte Tecnico datasource</description>

and the code connection snippet

Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/SoporteTecnico_DataSource");
conn = ds.getConnection("xxx", "xxx");

Increase VM memory for eclipse May 9, 2006

Posted by maxmil in : eclipse,Java,tomcat , 1 comment so far

Sometimes when running tomcat inside eclipse i've been getting VM out of memory errors.

To solve this problem..

Go to window->preferences->java-installed jre's->edit

and add the values:

-Xms512m -Xmx512m -Xss256k (or the amount of memory you want)

eclipse starts tomcat with those values.