Pages

Tuesday, December 31, 2013

Memory leak issue in tomcat [ "java.lang.OutOfMemoryError: PermGen space" error ]

Hi Guys,

While working with tomcat web application server with your J2EE web application, many times you come across the error as follows:

"java.lang.OutOfMemoryError: PermGen space" error

This error is because, the memory/space allocated to your tomcat process is not enough.
You can get rid of this problem by increasing JVM heap size.
To do so, here are the steps:

1. Go to CATALINE_BASE/bin/catalina.sh or CATALINE_BASE/bin/catalina.bat file.
2. make following entry in catalina.sh\catalina.bat file for JAVA_OPTS:

In Windows:

set JAVA_OPTS = -Xms1024m -Xmx10246m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m

In Linux:

export JAVA_OPTS="-Xms1024m -Xmx10246m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m"

You can change the actual heap size and PermGen Space as per your requirement.

Each of the otions are explained below.
•    Server – Run the tomcat in server mode. (the default is developer mode)
•    Xms – Minimum java heap space
•    Xmx – Maximum java heap space. While running on dedicated servers for production instances, keep both these options the same to ensure better utilization of available memory.
•    PermSize – The initial permSize. (default is 64MB)
•    Max PermSize – The maxPermSize. (even here, it may be a good idea to keep the intial and the max value the same).


3. Now, Restart your tomcat.

That's it...!!!
I hope this solutions works for you..
Please let me know, if you are still facing any issue even after following these steps.

Happy Coding...!!!
:)










Wednesday, December 11, 2013

Create J2EE MAVEN Project in Eclipse on Linux/Fedora/Unix

 Hi Guys,

Here I am going to show you the steps to configure J2EE maven project in Eclipse on Linux system:
I hope you are little bit aware of Maven and how to create a simple J2EE project in Maven.

1. Install jdk in your system.
2. Install maven in your system.
3. To configure maven, download maven tar ball and extract it in /usr/local folder.
4. set JAVA_HOME & MAVEN_HOME environment variables in your .bash_profile file.
  Steps:
1. login as root user
2. vi ~/.bash_profile
3. add following lines in it:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0
export PATH=$JAVA_HOME/bin:$PATH
export M2_HOME=/usr/local/apache-maven-3.1.1
export PATH=$M2_HOME/bin:$PATH
4. After adding the .bash_profile file, save and execute it to take it effect.
                   COMMAND:  source ~/.bash_profile
5. Add Maven plugIn in your eclipse IDE.
6. Go to Windows > Preferences > Maven Installation.
7. Add your local maven installation path over there. After that, it will update indexes. Let it finish.
8. Now, you are ready with maven installation.
9. To create new Maven project, Go to File> New> Maven> Maven Project. Create J2EE project with following artifact Id an group Id:
    artifact id: webapp-j2ee14
    group id: org.codehaus.mojo.archetypes

OR import existing project as maven project.

10. If you are deploying your web application on Tomcat and if you want to debug your project then refer:
        http://opensourcetechno.blogspot.in/2013/08/war-file-hot-deployment-issue-with.html
        http://opensourcetechno.blogspot.in/2012/11/remote-debug-on-tomcat-server-with-ant.html

11. When you deploy your web application, you may come accross "Permgen Space" exception on Tomcat Console. To resolve this, open your catalina.sh file (location:  <tomcat_home>/bin/) and make this entry for JAVA_OPTS.

JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

That's it...!!!
Please let me know if you face any issue while following this steps.

Happy Coding..!!
:)