farnett
farnett

Reputation: 480

java.lang.OutOfMemoryError: PermGen space after convering project to Maven

There are several questions on this topic and I went through all of the answers but I am still having the same problem. I am trying to implement spring security on an existing project that did not use spring previously. I successfully converted to a maven project and added a login form with no problems. I proceeded to make more changes, left for the day, came back the next and tomcat started throwing this error. I tried rolling back the changes I made and nothing made a difference, until I disabled the maven nature of the project. As soon as I did that, the error went away and as soon as I configure as maven project the error returns.

I have tried the following things as suggested in other stack overflow answers:

Originally Perm Generation was 99% however after adding -XX:PermSize=128M to eclipse.ini it went to a much lower percentage but this problem still persists

Thanks in advance! Any advice at all at this point would be helpful.

enter image description here

I either get one of two errors which are similar just different stack traces.

java.lang.OutOfMemoryError: PermGen space
Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
    at java.lang.Throwable.getStackTraceElement(Native Method)
    at java.lang.Throwable.getOurStackTrace(Throwable.java:591)
    at java.lang.Throwable.printStackTrace(Throwable.java:462)
    at java.lang.Throwable.printStackTrace(Throwable.java:451)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)

java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1148)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:1956)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1919)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1806)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1765)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1751)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1255)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:882)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:317)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5081)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Update: As suggested in the comments this seems to show exactly what the problem is. Perm Gen is shown totally full. What is the difference between this and what jmap (the other picture) is showing? One says 16MB and full the other says 128MB and room to spare. How do I increase the Perm Gen in this picture?

enter image description here

enter image description here

Upvotes: 3

Views: 8742

Answers (1)

hutingung
hutingung

Reputation: 1800

I believe you are using m2e plugin. If you are using m2e to execute maven proess, it will start a separate jvm. You need to configure VM argument for that process. Refer to screenshot below. You can try with a simple maven project first before apply to your project.

Sample pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
  1. Configure maven goal. Make sure select the project workspace and set maven goals correctly. You should use tomcat7:run if you are using tomcat7 plugin maven goal
  2. Configure VM arguments. Example: -Xmx1024m -Xms1024m -XX:MaxPermSize=512m -XX:PermSize=256m enter image description here
  3. Check the JVM argument that you set using JVisualVM. Select the process and get it from overview tab. Sample screenshot as below. enter image description here

Upvotes: 1

Related Questions