Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"java.lang.OutOfMemoryError: PermGen space" in Maven build [duplicate]

I'm getting this error while building Maven project, I increased MAVEN_OPTS but all the same, I found some similar posts but they are refering to something else. How do I fix this?

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.codehaus.plexus.compiler.javac.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:56)
        at com.sun.tools.javac.comp.Annotate.<init>(Annotate.java:52)
        at com.sun.tools.javac.comp.Annotate.instance(Annotate.java:36)
        at com.sun.tools.javac.jvm.ClassReader.<init>(ClassReader.java:215)
        at com.sun.tools.javac.jvm.ClassReader.instance(ClassReader.java:168)
        at com.sun.tools.javac.main.JavaCompiler.<init>(JavaCompiler.java:293)
        at com.sun.tools.javac.main.JavaCompiler.instance(JavaCompiler.java:72)
        at com.sun.tools.javac.main.Main.compile(Main.java:340)
        at com.sun.tools.javac.main.Main.compile(Main.java:279)
        at com.sun.tools.javac.main.Main.compile(Main.java:270)
        at com.sun.tools.javac.Main.compile(Main.java:87)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:420)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:141)
        at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:493)
        at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)

I'm not as worried about how to fix as to how to fix it in the maven ecosystem

like image 962
Gandalf StormCrow Avatar asked Oct 11 '22 23:10

Gandalf StormCrow


People also ask

How do I increase my PermGen space?

To fix it, increase the PermGen memory settings by using the following Java VM options. -XX:PermSize<size> - Set initial PermGen Size. -XX:MaxPermSize<size> - Set the maximum PermGen Size. In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.

What causes PermGen space error?

lang. OutOfMemoryError: PermGen Space is a runtime error in Java which occurs when the permanent generation (PermGen) area in memory is exhausted. The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays.

How do I set PermGen space in eclipse?

Open eclipse. ini file, it is located in root eclipse directory. there you can change -Xms and -Xmx parameter to change permgen size. There you can change -XX:PermSize and -XX:MaxPermSize.

How do I increase PermGen space in Weblogic?

To set PermGen size you can use e.g. -XX:PermSize=512m -XX:MaxPermSize=512m . Regarding Weblogic, set the JAVA_OPTIONS and see if these options are properly passed in as parameters into your Java process. You can also directly set these parameters in the startWeblogic.


2 Answers

When you say you increased MAVEN_OPTS, what values did you increase? Did you increase the MaxPermSize, as in example:

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"

(or on Windows:)

set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m

You can also specify these JVM options in each maven project separately.

like image 312
Arun R Avatar answered Oct 13 '22 12:10

Arun R


If you want to make this part of your POM for a repeatable build, you can use the fork-variant of a few of the plugins (especially compiler:compile and surefire:test):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
      <fork>true</fork>
      <meminitial>128m</meminitial>
      <maxmem>1024m</maxmem>
      <compilerArgs>
        <arg>-XX:MaxPermSize=256m</arg>
      </compilerArgs>
    </configuration>
  </plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
        <forkCount>1</forkCount>
        <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
    </configuration>
</plugin>
like image 24
eckes Avatar answered Oct 13 '22 13:10

eckes