Tuesday, July 19, 2011

Using Tomcat 6 Ant DeployTask

It has been a while since I've setup the Tomcat Ant tasks and thought I'd capture what it took for me to get it working.  I found some great references that made this easy:
The references were using older versions of Tomcat, so there were a few changes in the classpath I had to make.  I also had an issue with a forward slash located in the war attribute in the deploy task example I pulled from Matt Raible's site.

Here is what is working for me:
<path id="tomcat.classpath">
    <pathelement location="${tomcat.home}/bin/tomcat-juli.jar"/>
    <pathelement location="${tomcat.home}/lib/catalina-ant.jar"/>
    <pathelement location="${tomcat.home}/lib/jasper.jar"/>
    <pathelement location="${tomcat.home}/lib/servlet-api.jar"/>
</path>
<taskdef resourcce="org/apache/catalina/ant/catalina.tasks"
        classpathref="tomcat.classpath"/>

<target name="deploy" depends="make-war" if="tomcat.home"
        description="deploy Tomcat to the remote server">
    <deploy url="${manager.url}"
            username="${manager.username}"
            password="${manager.password}"
            path="${webappPath}"
            war="file:${dist.dir}/${webappPath}.war"
            update="true"/>
</target>

Friday, May 27, 2011

Redirecting port 80 on Linux

I recently installed a JEE application and wanted it to run on port 80 to simplify the URL. For security reasons I didn't want the process to run as root. When I tried to change the application servers config to attempt to bind port 80 I would receive this error:
Non root user cannot bind to port 80

After doing some research, I finally found the solution I decided to move forward with on Server Fault.

This allowed me to use iptables to redirect port 80 requests to port 8080:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Now I'm a happy admin as I get the security of not running the process as root and the pretty URL that doesn't require specifying the port!