Saturday, May 28, 2011

Install and Configure Tomcat6 on Ubuntu Linux

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.

The Java Servlet and JavaServer Pages specifications are developed under the Java Community Process.

Part 1
First, install tomcat6:
sudo apt-get install tomcat6 tomcat6-docs tomcat6-examples tomcat6-admin

Then configure a user to be manager and admin by adding the following lines
  <role rolename="admin"/>
  <role rolename="manager"/>
  <user username="YOURUSERNAME" password="YOURPASSWORD" roles="admin,manager"/>
in your /var/lib/tomcat6/conf/tomcat-users.xml. Make sure you put it between the <tomcat-users> and </tomcat-users> tags and don't forget to replace YOURUSERNAME with your actual username.
Now go to a browser and hit:
http://localhost:8080/
and you should see the welcome page.

Part 2
To restart tomcat you just need to say:
sudo /etc/init.d/tomcat6 restart
or if you want to start/stop/get status you just replace restart with start/stop/status.
To make this easier go to a terminal and type:
gedit tomcat
then add the following lines of text:
#!/bin/bash

/etc/init.d/tomcat6 $1
then save and close and type:
chmod u+x tomcat
sudo mv tomcat /usr/local/bin
so if you want to stop tomcat you can now say:
sudo tomcat stop
Let's add auto-completion to our new command now. Open a terminal and type:
gedit tomcat
then copy paste the following
_tomcat() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="start stop restart status"

    if [[ ${cur} == * ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _tomcat tomcat
save and close gedit. Now type:
sudo mv tomcat /etc/bash_completion.d
You need to restart for this to take effect, but if you want to test it right away type:
. /etc/bash_completion.d/tomcat
Then as an example, type:
sudo tomcat re
and hit tab a couple of times. It should complete the word restart for you since it's the only valid option that begins with "re".

No comments:

Post a Comment