Maven Jetty Plugin OutOfMemoryError When Sharing Instance Between Two Web Apps
Solution 1
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
Solution 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.
Solution 3
Try using Plumbr to diagnose any memory leak issues with both your web apps. http://plumbr.eu/
Related videos on Youtube
c12
Updated on September 16, 2022Comments
-
c12 over 1 year
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>
-
c12 over 10 yearsI tried your suggestion and even increased it to <jvmArgs>-XX:PermSize=512M -XX:MaxPermSize=1024M</jvmArgs> 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?
-
Snehal Patel over 10 yearsi am not aware about <jvmArgs> 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
-
Stephane over 8 yearsThe goal should be
run-forked
instead ofjetty:run-forked