Tag Archives: tomcat

Eclipse and Tomcat:java.lang.OutOfMemoryError: PermGen space

When run web application in eclipse with tomcat server you maybe get this issue:

java.lang.OutOfMemoryError: PermGen space

 

Solution

Increase JVM parameters

-XX:PermSize=<size>
-XX:MaxPermSize=<size>

You do as follow step to do that:

  • Open server on eclipse server tab
  • Choose Open launch configuration
  • Open Agurment-> add above parameters with increase to VM agurment session

For example i usually use

-XX:PermSize=256m
-XX:MaxPermSize=256m

deploy jax-ws or metro web services on tomcat server

When deploy jax-ws application on tomcat you maybe get this issue

SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoSuchMethodError: javax.xml.ws.soap.Addressing.responses()Ljavax/xml/ws/soap/AddressingFeature$Responses;
java.lang.NoSuchMethodError: javax.xml.ws.soap.Addressing.responses()Ljavax/xml/ws/soap/AddressingFeature$Responses;

This error occur cause the version JAXWS we use difference with the version JAX-WS ship with java. We can check version ship with java by run wsimport

in $JAVA_HOME/bin by follow command:

wsimport -version

So solution you can using wsimport or wsgen ship with java version to build web service or web service client.
But what happend if you still want using new version JAX-WS?
Well let me show you solution. The answer for that is using the endorsed overriding mechanism.
This guide will help you on Tomcat 6 and 7.

  • Create folder endorsed in $CATALINA_HOME
  • Copy following file in $JAXWS_HOME/lib jax-ws.api.jar,jaxb-api.jar,webservices-api.jar into endorsed

With above change your tomcat will work well with version JAX-WS that you want.
If it still not work so that must has problem on tomcat’s startup script(linux/unix). In that case you must add following parameter into startup script(linux/unix) in JAVA_OPTS parameters

 export JAVA_OPTS="$JAVA_OPTS" -Djava.endorsed.dirs="path of endoresed folder"

tomcat logging using log4j

In normal install tomcat use JULI for logging and this logging framework has issues on some advance rotation log file  configuration. I got issue with my hard disk always full after tomcat run for a couple of week cause log files. So i wonder if i can limit number of log files generate and tomcat reuse the old one when limit is reach.
After some research i find a solution. Tomcat allow us integration with log4j logging framework so we can handle above issue so easy.
If you have same problem i can guide you through.
Steps to make Tomcat work with log4j

We download two files from extras on tomcat download section

  • tomcat-juli.jar
  • tomcat-juli-adapters.jar

Copy tomcat-juli.jar to $CATALINA_HOME\bin to replace old one

Copy tomcat-juli-adapters.jar to $CATALINA_HOME\lib

Delete logging.properties in $CATALINA_HOME\conf

Create log4j.properties in $CATALINA_HOME\libs. This is sample of mine:

log4j.rootLogger=INFO, CATALINA

log4j.appender.CATALINA=org.apache.log4j.RollingFileAppender
#log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.log
log4j.appender.CATALINA.File=D:/catalina.log
log4j.appender.CATALINA.Encoding=UTF-8
log4j.appender.CATALINA.MaxBackupIndex=15
log4j.appender.CATALINA.layout=org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern=%d [%t] %-5p %c- %m%n
log4j.appender.CATALINA.MaxFileSize=10MB

Download log4j version greater than 1.2 and copy to $CATALINA_HOME\lib

After that restart tomcat.