Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.OutOfMemoryError: PermGen with Jenkins and Maven

I get the following exception in my Jenkins job:-

java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:201)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:149)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:86)
at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:64)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)

......

I run my Junit test cases in this job through Maven. As suggested by Jenkins I have a new global property MAVEN_OPTS with a value as high as -XX:MaxPermSize=1024m.
But still I continue to get the java.lang.OutOfMemoryError: PermGen.

Any assistance is greatly appreciated.

like image 815
Guru Prasad Venkatarao Avatar asked Dec 31 '13 05:12

Guru Prasad Venkatarao


2 Answers

Thanks Stefan for your answer. Unfortunately adding the default log4j classloader did not solve my issue. However the link provided by you solved the issue.

I had to add the following configuration in my "maven-surefire-plugin" definition:-

<argLine>-XX:PermSize=512m -XX:MaxPermSize=1024m</argLine>

This has fixed my problem.

like image 186
Guru Prasad Venkatarao Avatar answered Nov 02 '22 22:11

Guru Prasad Venkatarao


PowerMock has a memory leak caused by class loading stuff: https://code.google.com/p/powermock/issues/detail?id=346

You can use the default classloader for the log4j classes:

@RunWith(PowerMockRunner.class)
@PowerMockIgnore(value = {"org.apache.log4j.*"})
public class YourTest {
    ...
}
like image 27
Stefan Birkner Avatar answered Nov 03 '22 00:11

Stefan Birkner