Apache2 + Tomcat 5 + mod_jk2 Configuration

Posted by ryan
at 11:55 AM on Saturday, May 15, 2004

I’ve recently re-configured my mail/file/web server and thought it to be a good time to give an Apache2 + Tomcat 5 setup a second try. The last time I tried doing this I couldn’t ever figure out the whole Apache vs. Apache2 vs. mod_jserv vs. mod_jk vs. mod_jk2 thing. The supporting documentation has gotten a little better (see Apache’s JK docs), but it’s still lacking in a few areas.

The big differences I found between mod_jk and mod_jk2 are that you no longer have to have the “Jk” directives like “JkWorkersFile”, “JkLogFile” in the httpd.conf Apache file. Instead, Apache just looks in the /etc/httpd/conf/ directory for the workers2.properties file that will define the connector workers. In this new workers2.properties is where you define which contexts are passed off to Tomcat.

After finding a few others’ experiences on the web (you have to love Experts-Exchange), it turns out it’s a lot simpler than I originally thought. I wanted to use the latest and greatest, so I’m using Apache2 (httpd) + Tomcat 5.0.24 on Fedora Core 1 with the mod_jk2 connector.

Getting all the pieces used to this puzzle used to be somewhat of a chore, especialy the jk connectors, but Apache has made it a lot easier now.

After installing Apache2 and Tomcat 5, here’s what needs to happen to get Apache to talk to Tomcat:

  1. Copy the “mod_jk2.so” module you downloaded as part of the JK 2 Connector into the apache modules directory (/usr/lib/httpd/modules/)
  2. Copy the “workers2.properties” file also of the JK 2 Connector into the apache conf directory (/etc/httpd/conf/)
  3. Edit the httpd.conf Apache configuration file in /etc/httpd/conf/ and add this LoadModule directive:
    LoadModule jk2_module modules/mod_jk2.so
  4. Edit the /etc/httpd/conf/workers2.properties file to define which contexts you want Apache to hand off to Tomact. In my case, I have the “pebble” context that I want Tomcat to handle. This is what I added to the default workers2.properties file:
    [uri:/pebble/*]
    group=lb
    ...
  5. The default Tomcat 5 server.xml file has the necessary ajp13 connector configuration, but just in case here is the Connector definition (a child element of the <Service> element):
    <Connector
      className="org.apache.coyote.tomcat5.CoyoteConnector" 
      port="8009" minProcessors="5" maxProcessors="75" 
      enableLookups="true" redirectPort="8443" 
      acceptCount="10" debug="0" connectionTimeout="0" 
      useURIValidationHack="false" 
      protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
    

Restart httpd and tomcat and now when you go to http://localhost/tomcatContext, you should see your Tomcat context, served up through Apache!

Migrating VSS to CVS

Posted by ryan
at 12:44 PM on Friday, May 14, 2004

At my work we have a combination of “legacy” Visual Basic applications and more recent J2EE web based applications. The Visual Basic applications use the esteemed Visual Source Safe as their source code repository, whereas we were lucky enough to establish CVS for the Java apps. Well, VSS’s deficiencies in branching and merging have forced us to use CVS for all source (I say “forced”, but this is something I think is a good move and am totally for). So now the challenge is migrating our VSS repository to CVS and maintaining the code history.

The only such tool I have seen to accomplish this is this vss2cvs perl script. However, there doesn’t seem to be any account of a successful conversion effort. Well, this is my attempt to explain how I converted our VSS repository to CVS using this script… Note: I DO NOT claim to know perl. I basically hacked away at this till it worked, please let me know if you see a better way to accomplish any part of this script!

As I’m on a windows client machine, I had to install CygWin with the Perl libraries to execute this command for the transfer:

export CVSROOT=<i>your cvs root</i>
perl vss2cvs.pl SSROOT=//GRUEN/VSS SSPROJ=$/<i>your project</i>
CVSPROJ=<i>your new cvs proj name</i> SSUSERPASS=rdaigle,<i>your passwd</i>

But first, let’s get the script fixed:

  • First of all, it seems there needed to be some initial changes to the script outlined by this post.

Once I did that I was still getting errors about invalid SourceSafe syntax. Turns out the command line call to the VSS executable (ss.exe) was formatting the file path incorrectly. So I had to change that line in the script:

  • Line 122 changed from
    exec_cmd("ss workfold \"$ssproj\" \"$workdir\\$subdir\" 
    $ssuserpass");
    to
    exec_cmd("ss workfold \"$ssproj\" \"$workdir/$subdir\" 
    $ssuserpass");
  • After line 145 add the following to remove trailing ”:” from the directory names:
    $currdir =~ chomp($currdir);
    $currdir =~ chop($currdir);
  • Before Line 168: (
    open(FILETYPE,"ss filetype \"$currfile\" $ssuserpass |");
    add
    $currfile =~ s/\r//g;
    to remove leading spaces from the path.
  • Line 237 of sub resync_file: add
    $file =~ s/^ *//;
    to remove leading slashes from file path

After that, I started getting erros about not being a CVS module. Turns out the script was trying to get modules from CVS that hadn’t yet been moved over from VSS (the script claims to be able to re-sync repositories, I have not tried this).

  • Wrap the
    open(CVS,"$cvscmd |");
    and subsequent while loop with this “if” statement:
    if ($alreadyincvs)

Ok, good. At this point I started getting “attempting to use variables not yet initialized” errors and needed to check that the “highestssver” variable at line 424 was initialized before using it.

At this point I noticed that it wasn’t properly finding the labels and had to:

  • change line 433 from
    if(/^Label: "(.+)"$/)
    to
    if(/^Label:/) 

Here is the resulting file that seems to work pretty well for me: (right click -> save as…). Please let me know if I need to clarify anything or what your experiences are with this conversion. There seems to be a lot of interest in it, with very little real solutions. Hopefully we can remedy that and get people off VSS.

As a side note, here is where the script falls short:

  • Tags (or “labels” in VSS) don’t seem to get transferred over.
  • Branches, forget about it.
  • The user and date of the original commit to VSS won’t show accurately in CVS. Instead, the comments for each commit will contain the original user and date. However, I have seen somewhere that executing this *nx command under your CVSROOT will remedy this:
    find . -name \*,v -print | while read f; do massagecomments.pl
    "$f"; done
    “massagecomments.pl” can be found at the original vss2cvs.pl download location mentioned at the beginning of the post.

Let me know how it goes.

Paul Glaubitz has kindly given me the updated script he used that properly handles file labels. I’ve updated these links with his version. Thanks, Paul!

Here are the resources mentioned in this post: (right click -> save as…)