Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PermGen space with jetty

I'm developing a java web application where I'm using mavenlike tool of project managment. Now my trouble is that if i setted jetty for autoscan each 20 second in this way:

<!-- To launch embded jetty server -->
       <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                    <extraClasspath>target/classes;../services/target/classes;</extraClasspath>
                </webAppConfig>
                <scanTargets>
                    <scanTarget>target/classes</scanTarget>
                    <scanTarget>../services/target/classes</scanTarget>
                </scanTargets>
            </configuration>
        </plugin>

Jetty starts in a correct way in fact i get:

[INFO] Started Jetty Server

[INFO] Starting scanner at interval of 20 seconds.

But at the first scan i get the following error:

ERROR ContextLoader - Context initialization failed

java.lang.OutOfMemoryError: PermGen space

How can I do to fix it?

Update 1

I try to increse a PermGen space from my Eclipse Ide in this way:

enter image description here

but after the first scan i get back the same error.

How can I do to fix it?

like image 581
Skizzo Avatar asked Feb 05 '14 14:02

Skizzo


2 Answers

Put this under the <configuration> element: <jvmArgs>-XX:PermSize=256M -XX:MaxPermSize=512M</jvmArgs>

So the Maven plugin will look like this:

<!-- To launch embded jetty server -->
       <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <jvmArgs>-XX:PermSize=256M -XX:MaxPermSize=512M</jvmArgs>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                    <extraClasspath>target/classes;../services/target/classes;</extraClasspath>
                </webAppConfig>
                <scanTargets>
                    <scanTarget>target/classes</scanTarget>
                    <scanTarget>../services/target/classes</scanTarget>
                </scanTargets>
            </configuration>
        </plugin>

NOTE: if it fails with a message that it can't allocate so much memory use lower numbers.

like image 65
Jiri Kremser Avatar answered Nov 02 '22 16:11

Jiri Kremser


Have you tried running under JDK8? PermGen has been replaced with MetaSpace and might fix your PermGen issues: http://www.infoq.com/news/2013/03/java-8-permgen-metaspace

Jetty also has some documentation about preventing classloader leaks that might fill up permgen: http://www.eclipse.org/jetty/documentation/current/preventing-memory-leaks.html

like image 5
Bill Brasky Avatar answered Nov 02 '22 16:11

Bill Brasky