Skizzo
Skizzo

Reputation: 2983

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?

Upvotes: 5

Views: 2058

Answers (3)

Jiri Kremser
Jiri Kremser

Reputation: 12837

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.

Upvotes: 6

Bill Brasky
Bill Brasky

Reputation: 2644

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

Upvotes: 5

INeedMySpace
INeedMySpace

Reputation: 315

Try to increase MaxPermGen space with -XX:MaxPermSize=512m passed to MAVEN_OPTS.

Upvotes: 1

Related Questions