twitter
    Find out what I'm doing, Follow Me :)
Showing posts with label tomcat 7. Show all posts
Showing posts with label tomcat 7. 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 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