OutOfMemoryError while deploying a war from Jenkins to Tomcat OutOfMemoryError while deploying a war from Jenkins to Tomcat shell shell

OutOfMemoryError while deploying a war from Jenkins to Tomcat


As the exception indicates your problem comes from filling up the PermGen space. It is a part of memory where Java stores the metadata about your classes (let's say the code of your loaded classes). When you deploy a new web-app you add new classes and increase the load of PermGen. What is worse, when you re-deploy the same app in 90% of the cases, the previous versions of the used classes stays in the memmory so you do not release the 'old' memory from PermGen but just add to it (the 90% estimation comes from using DataBase drivers, frameworks which uses ThreadLocal, Scheduler threads ... in reality it happens almost all the time).

The default permgen is too small (like 64M or something as ridiculous). Start tomcat with higher values, you do it by passing to tomcat the JVM options, for example:

JAVA_OPTS = -XX:MaxPermSize=512m -Xmx4024m

(first set the perm size to 512MB second the heap size to 4G, which is fine for modern system).

You set this variable before you start tomcat, or (I prefer it that way, you can modify your /bin/catalina script to always have them set up there, that way you will not 'forget' them if you start your tomcat again).

From tomact 7, when you undeploy app, the tomcat logs show warnings of apps that stays in memmory (and fill up your PermGen), you may want to check them and try to fix some problems (updating frameworks, shuting down properly your threads pool ...)