4

I'm using the maven jetty plugin to run my two web applications. One web application is spring mvc UI and the other is a RESTful web application. I able to get the two web applications to communicate when I run two separate mvn jetty:run instances and assign different ports. I have successfully deploy both in the same jetty instance using the same port using the below maven pom.xml configuration. I eventually get a ava.lang.OutOfMemoryError: PermGen space error. What is the best workaround for this?

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.6.8.v20121106</version>
    <configuration>
        <jvmArgs>-Xmx2024m -Xms2024m</jvmArgs>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <webApp>
            <contextPath>/</contextPath>
        </webApp>
        <contextHandlers>           
            <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                <war>../../api/target/main-api.war</war>
                <contextPath>/test</contextPath>
            </contextHandler>
        </contextHandlers> 
    </configuration>
</plugin>
Gwenc37
  • 2,064
  • 7
  • 18
  • 22
c12
  • 9,557
  • 48
  • 157
  • 253

6 Answers6

10

Add following jvm argument, if you get error regarding cannot allocate memory then try using lesser value (128 and 256)

-XX:PermSize=256M -XX:MaxPermSize=512M

Reference

Community
  • 1
  • 1
Snehal Patel
  • 819
  • 6
  • 9
  • I tried your suggestion and even increased it to -XX:PermSize=512M -XX:MaxPermSize=1024M but I still get a java.lang.OutOfMemoryError: PermGen space. Also, I can't cntrl + c the jetty server and have to kill the process when I have the configuration like I listed above. Is it common to run two jetty instances (one per web app) from one maven pom.xml? – c12 Sep 07 '13 at 16:46
  • 1
    i am not aware about parameter for maven plugin, will you please try setting memory related parameter in MAVEN_OPTS environment variable, e.g. on windows set MAVEN_OPTS=-Xms1024m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=512M and then execute mvn – Snehal Patel Sep 09 '13 at 05:03
2

Try running Jetty in forked mode like this:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.6.8.v20121106</version>
    <executions>
        <execution>
          <id>start-jetty</id>
          <!-- Set this to the appropriate phase:
               pre-integration-test, or earlier test-compile-->
          <phase>pre-integration-test</phase>
          <goals>
             <goal>run-forked</goal>
          </goals>
       </execution>
    </executions>

    <configuration>
        <jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=128m -XX:MaxPermSize=256m</jvmArgs>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <webApp>
            <contextPath>/</contextPath>
        </webApp>
        <contextHandlers>           
            <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                 <war>../../api/target/main-api.war</war>
                <contextPath>/test</contextPath>
            </contextHandler>
        </contextHandlers> 
    </configuration>
</plugin>

For more details check Running Jetty in a forked JVM.

And... Make sure you really have 2048 MB of free RAM before starting this.

carlspring
  • 31,231
  • 29
  • 115
  • 197
1

Try using Plumbr to diagnose any memory leak issues with both your web apps. http://plumbr.eu/

Chris Harris
  • 1,329
  • 4
  • 17
  • 28
0

I eventually get a java.lang.OutOfMemoryError: PermGen space error

How long is eventually? Is one of the webapps redeploying frequently due to changes?

It is very easy to leak classes when redeploying a web app. I would run maven with this setting added to MAVEN_OPTS

-XX:+HeapDumpOnOutOfMemoryError

Run until you get an out of memory error, then load the dump with eclipse mat and see what is filling up your perm gen. Most likely your web app is leaking classes on redeploy.

sbridges
  • 24,960
  • 4
  • 64
  • 71
0

It depends on which JVM instance require more memory. As example, if tests are forked (by default), and fails due OutOfMemoryError then try configure plugin which launching them:

   <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <argLine>-Xmx1024m</argLine>
        </configuration>
    </plugin>

OR

Apart from heap memory. You have to increase perm size also to resolve that exception in maven use these variables in environment variable. And Sometimes is good also to extend perm memory size -

Set the environment variable:

variable name: MAVEN_OPTS variable value: -Xmx512m -XX:MaxPermSize=256m

Compiled data from resource

Community
  • 1
  • 1
Digital Alchemist
  • 2,324
  • 1
  • 15
  • 17
0

Please clarify: what jvm version you are using, what operating system you are on, how many physical memory is installed on your computer. What happen if you reduce your memory requirements for example to 1400M (it could help if you run on 32bit jvm), i.e.:

<jvmArgs>-Xmx1400m -Xms1400m</jvmArgs>
Andrew
  • 179
  • 2
  • 9