twitter
    Find out what I'm doing, Follow Me :)
Showing posts with label apache tomcat. Show all posts
Showing posts with label apache tomcat. Show all posts

Parancoe 3 web framework

Parancoe is a project aiming to simplify the release of web applications promoting the convention over configuration philosophy and the DRY principle. This project is promoted by the JUG Padova, and everybody can partecipate.
Parancoe is a Java meta-framework aggregating in an useful way Hibernate/JPA, Spring 2, Spring MVC and, for the AJAX support, DWR.
Parancoe purpose is to give to developers a set of libraries ready to build standard web applications (which in most cases are just crud applications) without worrying of long and harmful configurations files. Parancoe will be composed of a full MVC stack.
Parancoe is open source and is released under the Apache License, Version 2.0.
Are you interested in the parancoe word meaning? A “parancoa” is a scaffolding in the dialect of the Venice (Italy) area.

Lot of time I don’t post something…
But the development of Parancoe is not death. I’m working at the next major release: Parancoe 3.0!
Some of the changes:
  • The persistence (generic DAOs) has its own independent project now: Lambico. It’s more evolved and robust.
  • Parancoe now uses Spring 3.0, with it latest evolution and improvements.
  • The suggested style for developing the controllers is the REST one.
  • The validation is JSR 303 – Bean Validation (according to Spring MVC 3.0).
  • We have a new subproject called Parancoe – Validation, for introducing some useful validator, ready for use. (what about a “new password” validator?)
You can start trying Parancoe 3 using the snapshots: Parancoe artifacts are already in our Maven snapshot repository.
For starting a new project based on Parancoe 3, use the “Parancoe Advanced Archetype”, typing the following command:

mvn -DarchetypeGroupId=org.parancoe \
-DarchetypeArtifactId=parancoe-advancedarchetype \
-DarchetypeVersion=3.0-SNAPSHOT \
-DarchetypeRepository=https://oss.sonatype.org/content/repositories/snapshots \
-Darchetype.repository=https://oss.sonatype.org/content/repositories/snapshots \
-Darchetype.interactive=false \
-DgroupId=org.myorg \
-DartifactId=myapp \
-Dpackage=org.myorg.padt \
-Dversion=1.0-SNAPSHOT \
--batch-mode \
--update-snapshots \
org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate


project page: http://www.parancoe.org/

Increasing Permgen size in your Web Server

In previous posts , we had talked about Increasing the Heap size of your server
Here will talk about the Permgen space , how it is different from heap size and why just increasing the heap size will not help you in getting rid of this error 
Java.lang.OutOfMemoryError: PermGen space

The permanent generation should not be ignored, because you need enough memory allocated to it to hold all classes in all of your applications including the JSP’s. So if you have an application which uses a good number of third party libraries , has lot of files , you will definitely need a lot of Permgen space. If you are running two applications on the same server , definitely allocate some good chunk of memory to your Perm gen.

How to increase PermGen?

When you add this line in your catalina.bat or catalina.sh

export JAVA_OPTS=-Xms128m -Xmx192m

It only increase heap size. This is how it would look like (assuming your default PermGen is 64MB)

Increasing PermGen on tomcat

PermGen does not change
To increase PermGen , it would be

export JAVA_OPTS=-Xms128m -Xmx192m -XX:MaxPermSize=256m

See how the size of PermGen has increased.

Perm Gen increased

Perm Gen increased
This was done on Tomcat 6.0.14

How to increase heap size in Tomcat 6

Most of us who have worked with Apache-Tomcat in productions systems, would have faced out of memory errors sometimes or other.  It is not that it always happens in tomcat but let us look at why does this occur and how to solve it.

 

Understanding Java Virtual Machine 

A Java Virtual Machine on 32-bit operating systems typically has a maximum heap size of 64Mb. The JVM heap space is where all Java objects are stored, as well as memory used by the garbage collector. Sun recommends increasing this value for server applications.

Large server applications often experience two problems with these defaults. One is slow startup, because the initial heap is small and must be resized over many major collections. A more pressing problem is that the default maximum heap size is unreasonably small for most server applications.
64MB  is the heap size in tomcat as well by default and is too less for real world systems. When your application runs and you are able to analyze the app, this is what you would see

heap size in tomcat
heap size in tomcat 

How to increase the heap size?

On windows :

Go to catalina.bat and set this
set JAVA_OPTS=-Xms128m -Xmx192m

On linux :

export CATALINA_OPTS="-Xms16m -Xmx256m";

-Xms – is the minimum or initial size of your heap
-Xmx – is the maximim size

export JAVA_OPTS="-Xms128m -Xmx256m";

On linux , you can also set in setenv.shin the bin folder. The catalina.sh script has logic to call into this script.

Note that CATALINA_OPTS is a better place than JAVA_OPTS. The former is only used when actually starting the Tomcat instance. JAVA_OPTS is also used to start JVMs that only interact with Tomcat (for example the JVM instance that is used to send the shutdown-message to a running Tomcat instance).

You can have a look at this article High Performance in Tomcat. Although this article is pretty old (dates back to Tomcat 4) , it still has lot of good points.
Once you have set the heap , how to check heap size ?

How to check heap size in linux

The output of jmap -heap <pid>.
Some more information can be found here http://wiki.apache.org/tomcat/OutOfMemory

Install Tomcat 6 on Ubuntu 10.04 by apt-get

Apache Tomcat is a web container that allows you to serve Java Servlets and JSP (Java Server Pages) web applications.

The Tomcat 6.0 packages in Ubuntu support two different ways of running Tomcat. You can install them as a classic unique system-wide instance, that will be started at boot time and will run as the tomcat6 unpriviledged user. But you can also deploy private instances that will run with your own user rights, and that you should start and stop by yourself. This second way is particularly useful in a development server context where multiple users need to test on their own private Tomcat instances.

System-wide installation

To install the Tomcat server, you can enter the following command in the terminal prompt:

sudo apt-get install tomcat6
This will install a Tomcat server with just a default ROOT webapp that displays a minimal "It works" page by default.

Configuration

Tomcat configuration files can be found in /etc/tomcat6. Only a few common configuration tweaks will be described here, please see Tomcat 6.0 documentation for more.

Changing default ports

By default Tomcat 6.0 runs a HTTP connector on port 8080 and an AJP connector on port 8009. You might want to change those default ports to avoid conflict with another server on the system. This is done by changing the following lines in /etc/tomcat6/server.xml:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
               redirectPort="8443" /&rt;
...
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&rt;

Changing JVM used

By default Tomcat will run preferably with OpenJDK-6, then try Sun's JVM, then try some other JVMs. If you have various JVMs installed, you can set which should be used by setting
JAVA_HOME in /etc/default/tomcat6:

JAVA_HOME=/usr/lib/jvm/java-6-sun

Declaring users and roles

Usernames, passwords and roles (groups) can be defined centrally in a Servlet container. In Tomcat 6.0 this is done in the /etc/tomcat6/tomcat-users.xml file:


Using Tomcat standard webapps

Tomcat is shipped with webapps that you can install for documentation, administration or demo purposes.

Tomcat documentation

The tomcat6-docs package contains Tomcat 6.0 documentation, packaged as a webapp that you can access by default at http://yourserver:8080/docs. You can install it by entering the following command in the terminal prompt:

sudo apt-get install tomcat6-docs

Tomcat administration webapps

The tomcat6-admin package contains two webapps that can be used to administer the Tomcat server using a web interface. You can install them by entering the following command in the terminal prompt:

sudo apt-get install tomcat6-admin
The first one is the manager webapp, which you can access by default at http://yourserver:8080/manager/html. It is primarily used to get server status and restart webapps.
[Note]
Access to the manager application is protected by default: you need to define a user with the role "manager" in /etc/tomcat6/tomcat-users.xml before you can access it.

The second one is the host-manager webapp, which you can access by default at http://yourserver:8080/host-manager/html. It can be used to create virtual hosts dynamically.
[Note]
Access to the host-manager application is also protected by default: you need to define a user with the role "admin" in /etc/tomcat6/tomcat-users.xml before you can access it.

For security reasons, the tomcat6 user cannot write to the /etc/tomcat6 directory by default. Some features in these admin webapps (application deployment, virtual host creation) need write access to that directory. If you want to use these features execute the following, to give users in the tomcat6 group the necessary rights:

sudo chgrp -R tomcat6 /etc/tomcat6
sudo chmod -R g+w /etc/tomcat6

Tomcat examples webapps

The tomcat6-examples package contains two webapps that can be used to test or demonstrate Servlets and JSP features, which you can access them by default at http://yourserver:8080/examples. You can install them by entering the following command in the terminal prompt:

sudo apt-get install tomcat6-examples

Using private instances

Tomcat is heavily used in development and testing scenarios where using a single system-wide instance doesn't meet the requirements of multiple users on a single system. The Tomcat 6.0 packages in Ubuntu come with tools to help deploy your own user-oriented instances, allowing every user on a system to run (without root rights) separate private instances while still using the system-installed libraries.
[Note]
It is possible to run the system-wide instance and the private instances in parallel, as long as they do not use the same TCP ports.

Installing private instance support

You can install everything necessary to run private instances by entering the following command in the terminal prompt:

sudo apt-get install tomcat6-user

Creating a private instance

You can create a private instance directory by entering the following command in the terminal prompt:

tomcat6-instance-create my-instance
This will create a new my-instance directory with all the necessary subdirectories and scripts. You can for example install your common libraries in the lib/ subdirectory and deploy your webapps in the webapps/ subdirectory. No webapps are deployed by default.

Configuring your private instance

You will find the classic Tomcat configuration files for your private instance in the conf/ subdirectory. You should for example certainly edit the conf/server.xml file to change the default ports used by your private Tomcat instance to avoid conflict with other instances that might be running.

Starting/stopping your private instance

You can start your private instance by entering the following command in the terminal prompt (supposing your instance is located in the my-instance directory):

my-instance/bin/startup.sh
[Note]
You should check the logs/ subdirectory for any error. If you have a java.net.BindException: Address already in use:8080 error, it means that the port you're using is already taken and that you should change it.
You can stop your instance by entering the following command in the terminal prompt (supposing your instance is located in the my-instance directory):

my-instance/bin/shutdown.sh

References

Install Tomcat 6 on Ubuntu


If you are running Ubuntu and want to use the Tomcat servlet container, you should not use the version from the repositories as it just doesn’t work correctly. Instead you’ll need to use the manual installation process that I’m outlining here.

Before you install Tomcat you’ll want to make sure that you’ve installed Java. I would assume if you are trying to install Tomcat you’ve already installed java, but if you aren’t sure you can check with the dpkg command like so:


dpkg –get-selections | grep sun-java

This should give you this output if you already installed java:


sun-java6-bin install
sun-java6-jdk install
sun-java6-jre install

If that command has no results, you’ll want to install the latest version with this command:


sudo apt-get install sun-java6-jdk

Installation

Read my post for last JDK http://diegobenna.blogspot.com/2011/01/install-jdk-6-update-21-in-ubuntu-1010.html or follow:


sun-java6-bin install
sun-java6-jdk install
sun-java6-jre install

Now we’ll download and extract Tomcat from the apache site. You should check to make sure there’s not another version and adjust accordingly.


wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz
tar xvzf apache-tomcat-6.0.14.tar.gz

The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat, but you could move it somewhere else if you wanted to.


sudo mv apache-tomcat-6.0.14 /usr/local/tomcat

Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose.

The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect.


vi ~/.bashrc

Add the following line:


export JAVA_HOME=/usr/lib/jvm/java-6-sun

At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder.

Automatic Starting

To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.


sudo vi /etc/init.d/tomcat

Now paste in the following:


# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

You’ll need to make the script executable by running the chmod command:


sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.


sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tomcat should now be fully installed and operational. Enjoy!


sudo /etc/init.d/tomcat restart

Preventing Tomcat java.lang.OutOfMemoryError: PermGen space failure


The "OutOfMemoryError: PermGen space" message is normally encountered during development activites where a long-running JVM is asked to load/unload builds. However it can also be encountered in a recently spawned JVM under the "right" set of conditions.

The message is a symptom of an incomplete garbage collection sweep where resources are not properly released upon unload/restart.

Tomcat production server sometime will hit the following java.lang.OutOfMemoryError: PermGen space error.

java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)

It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, you should increase the memory by make change in catalina.sh or catalina.bat file.

How to fix it?

1) Find where is Cataline.sh located. We need to make some changes in "catalina.sh" file.
P.S Cataline.sh is located at \tomcat folder \bin\catalina.sh

2) Assign following line to JAVA_OPTS variable and add it into catalina.sh file.
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

Partial example of the catalina.sh file
# JSSE_HOME (Optional) May point at your Java Secure Sockets Extension
# (JSSE) installation, whose JAR files will be added to the
# system class path used to start Tomcat.
#
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $
# -----------------------------------------------------------------------------

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m
-Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"


# OS specific support. $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

3) Done. Restart Tomcat.
You should change the “Xms” and “PermSize” value base on your server capability.

Connect Tomcat 7 with Apache2 (mod_jk) and install Virtual Host

Virtual hosting is a method for hosting multiple domain names on a computer using a single IP address. This allows one machine to share its resources, such as memory and processor cycles, to use its resources more efficiently.

One widely used application is shared web hosting. Shared web hosting prices are lower than a dedicated web server because many customers can be hosted on a single server.

Installa Apache Tomcat 7:
http://diegobenna.blogspot.com/2011/01/install-tomcat-7-in-ubuntu-1010.html

and install Apache2:
http://diegobenna.blogspot.com/2011/01/install-apache2-with-php5-and-mysql.html

Install the connector:
sudo apt-get install libapache2-mod-jk

Now we move on to configure it to communicate with Apache Tomcat.
The first step is to create a file folder worker.properties apache like this:
sudo gedit /etc/apache2/workers.properties

End insert this text:
# Define 1 real worker using ajp13
worker.list=worker
# Set properties for worker (ajp13)
worker.worker.type=ajp13
worker.worker.host=localhost
worker.worker.port=8009

If you want add a new application in Virtual Web Host is not necessary to add a new workerX

Edit this file for connect tomcat's application with apache2:
sudo gedit /etc/apache2/httpd.conf

Past and copy this text:

ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

Now we just have to disable the default configuration file for apache with:
sudo a2dissite default

We must also remove the line NameVirtualHost *: 80 as follows:
sudo gedit /etc/apache2/ports.conf

Reload e restart apache2
sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 restart

Edit file jk.load for load tomcat webapps in apache2 avaible web site

cd /etc/apache2/mods-available
sudo gedit jk.load

Past and copy this text:


LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

And now edit proxy.conf


sudo gedit proxy.conf

This is new text:

<IfModule mod_proxy.c>
#turning ProxyRequests on and allowing proxying from all may allow
#spammers to use your proxy to send email.

ProxyRequests Off

<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
#Deny from all
#Allow from .example.com
</Proxy>

# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block

ProxyVia On
</IfModule>

Create the symbolik link in apache web site avaible:
cd /etc/apache2/mods-enabled 
sudo ln -s ../mods-available/jk.load ./jk.lo

We add in mods-enabled also links to the following modules
rewrite.load
proxy.load
proxy.conf
proxy_ajp.load


sudo ln -s ../mods-available/rewrite.load ./rewrite.load
sudo ln -s ../mods-available/proxy.load ./proxy.load
sudo ln -s ../mods-available/proxy.conf ./proxy.conf
sudo ln -s ../mods-available/proxy_ajp.load ./proxy_ajp.load


Create and edit the application's file (genetic is my web application name):
sudo gedit /etc/apache2/sites-available/genetic

Copy and past this text:

NameVirtualHost www.genetic.it:80
<VirtualHost www.genetic.it:80>
ServerName www.genetic.it
JKMount /genetic/* worker
JKMount /genetic worker

  RewriteEngine on
  RewriteRule ^/$ /genetic/ [R=permanent]
  RewriteRule ^/genetic/(.*)$ ajp://localhost:8009/genetic/$1 [P]
</VirtualHost>

Create a symbolic link in enabled directory:

cd /etc/apache2/sites-enabled
sudo ln -s ../sites-available/genetic ./001-genetic

Let's create an application to be addressed
sudo gedit /usr/share/tomcat7/conf/server.xml

Add this text to hosts:

...
<Host name="www.genetic.it" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="true" xmlNamespaceAware="false">
<Context path="" docBase="genetic/" reloadable="true" privileged="true" antiResourceLocking="false" anitJARLocking="false">
</Context>
</Host>
...

I create the folder for the application if the application does not exist

sudo mkdir /usr/share/tomcat7/webapps/genetic
cd /usr/share/tomcat7/webapps/genetic

Install application
sudo jar xvf genetic.war

Now your virtualhost in internet is actived. If you want virtualhost in localhost, edit hosts file:

sudo gedit /etc/hosts

Add in the line starting with 127.0.0.1

www.genetic.it

Install module rewrite
sudo a2enmod rewrite

Restart tomcat and reload Apache2

sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/tomcat7 restart

Write in your browser:
www.genetic.it
and see your tomcat webapp in apache

Install Tomcat 7 on Ubuntu 12.04




Apache has officially launched version 7.0 of the servlet container for Java applications, Tomcat. Major changes in this version, you can highlight support for Servlet 3.0 and JavaServer Pages 2.2.

Install JDK
See this post: Install JDK 6 update 23 in Ubuntu 10.10

Installation

The first thing to do is download the package "apache-tomcat-7.0.6.tar.gz" from the NEXT link
http://tomcat.apache.org/download-70.cgi [tar.gz]
Now unpack it with the following command:
tar xvzf apache-tomcat-7.0.8.tar.gz

Then we let in a more appropriate directory, in our case in / usr/share/tomcat7, but can be in any directory. We do this with the command:
sudo mv apache-tomcat-7.0.8/ /usr/share/tomcat7

Now we define the environment variables JAVA_HOME and JRE_HOME. This file is in the "environment" in / etc. Command to edit the file:
sudo gedit /etc/environment

Here we record the routes where we have installed Java in my case this is as follows:

JAVA_HOME="/usr/local/jdk1.6.0_23"
JRE_HOME="/usr/local/jdk1.6.0_23/jre"
PATH="...(other path):$JAVA_HOME:$JRE_HOME"

IMPORTANT: Verify the routes where they have installed Java.

I have had some problems in defining these environment variables, as sometimes tomcat does not recognize, but a surefire way of recognizing that tomcat is to define the file paths inside "catalina.sh"located in tomcat7/bin. To modify this file use the command:
sudo gedit /usr/share/tomcat7/bin/catalina.sh

Now just insert the JAVA_HOME and JRE_HOME after the first line, so the file is as follows:
#!/bin/sh
JAVA_HOME="/usr/local/jdk1.6.0_23"
JRE_HOME="/usr/local/jdk1.6.0_23/jre"
# Licensed to the Apache Software Foundation (ASF)...
#...
#...
....

Now let's configure Tomcat users, this is done in the file "tomcat-users.xml"directory tomcat7/conf. Command to edit the file:
sudo gedit /usr/share/tomcat7/conf/tomcat-users.xml

Unlike previous versions where the administrator should own role "manager" now it should be "manager-gui"to operate on the web administration tomcat7. The file would be as follows:


<?xml version='1.0' encoding='utf-8'?>

<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="admin"/>

<user username="usuario" password="contrasena" roles="manager-gui,admin-gui,manager,admin,manager-script,admin-script"/>
</tomcat-users>



Now you should be all ready to try tomcat7.

First we must lift the server with the following command:
sudo /usr/share/tomcat7/bin/startup.sh

With this we get the following output on console:
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using JRE_HOME: /usr/local/jdk1.6.0_20/jre
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar

Verify that the JRE_HOME is where we define.

Now open your web browser and type the following url:
http://127.0.0.1:8080/

So we get the following page:

If we enter the administration Tomcat Manager we click on the menu or directly at URL:
http://127.0.0.1:8080/manager/html

Here we ask the user data from previous record in mind tomcat-users.xml.

I recommend testing the sample to make sure everything works ok, they are in the section "Miscellaneous" from the side menu or at the URL:
http://127.0.0.1:8080/examples/

Commands

Start server:
sudo /usr/share/tomcat7/bin/startup.sh

Stop server:
sudo /usr/share/tomcat7/bin/shutdown.sh

Automatic Starting

To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.


sudo gedit /etc/init.d/tomcat7

Now paste in the following:


# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

case $1 in
start)
sh /usr/share/tomcat7/bin/startup.sh
;;
stop)
sh /usr/share/tomcat7/bin/shutdown.sh
;;
restart)
sh /usr/share/tomcat7/bin/shutdown.sh
sh /usr/share/tomcat7/bin/startup.sh
;;
esac
exit 0

You’ll need to make the script executable by running the chmod command:


sudo chmod 755 /etc/init.d/tomcat7

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.


sudo ln -s /etc/init.d/tomcat7 /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat7 /etc/rc2.d/S99tomcat

Tomcat should now be fully installed and operational. Enjoy!

sudo /etc/init.d/tomcat7 restart