28

I want to start an embedded tomcat7 instance directly from maven using the tomcat7-maven-plugin. This is working fine, but the Tomcat started doesn't seem to have enough memory. I suspect that I would need to set

-XX:MaxPermSize=256m

but I can't figure out how to do it.

The documentation says one should use the "systemProperties" element in the "configuration" section of the plugin. However, the options are specified as XML elements and would need to look like that:

<configuration>
  <systemProperties>
    <XX:MaxPermSize>256m</XX:MaxPermSize>
  </systemProperties>
</configuration>

But that's of course not possible as it breaks the XML (XX is interpreted as a namespace).

Of course I could get around this problem by setting environment variable

MAVEN_OPTS=-XX:MaxPermSize=256m

but I would prefer to only increase it for the embedded Tomcat. Any ideas how to do that?

Sebi
  • 8,323
  • 6
  • 48
  • 76

3 Answers3

14

As most said in the comments above the properties in pom.xml has no effct. What worked for me was setting my MAVEN_OPTS

MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"

Or on Windows in a cmd terminal:

set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m

For mac/linux users, just add an export statement to your ~/.profile (or similar file name). For example:

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"

And restart your shell.

Lennart Kramer
  • 141
  • 1
  • 2
  • Of course the maven property I mentioned in my answer is not changing the memory for the Maven process, but for the Tomcat process started by Maven. That's what the original poster asked: How to increase memory of tomcat7 maven plugin! – Sebi Oct 06 '14 at 17:29
  • 2
    The problem is that your solution _Sebi_ does *not* change the memory of the started Tomcat process as like _rzrelyea_ already pointed out above, no separate Tomcat process is started at all. – Jan Schaefer Mar 08 '15 at 07:07
  • Be careful if you're using a "forking" surefire test runner, it may not respect MAVEN_OPTS...http://stackoverflow.com/questions/4066424/java-lang-outofmemoryerror-java-heap-space-in-maven – rogerdpack Apr 20 '15 at 13:34
  • Maybe using the fork plugin parameter ? I don't actually know if it works ? I'll have a try of this one. – Tony Chemit Jan 26 '16 at 09:12
  • I tried that solution and on Java 8 it gives the following warning: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0 – Nestor Milyaev Nov 09 '16 at 19:47
3

You can set the properties in this way

<configuration>
  <systemProperties>
    <JAVA_OPTS>-Xms256m -Xmx512m -XX:MaxPermSize=256m</JAVA_OPTS>
  </systemProperties>
</configuration>
Rene Herget
  • 1,506
  • 13
  • 28
  • 11
    This didn't actually work for me at all, and I wouldn't really expect it to. The java process has already started and it seems that [even if you fork, you still don't get a new java process](http://mojo.10943.n7.nabble.com/How-to-set-user-timezone-within-tomcat-maven-plugin-td36517.html). So I think you have to set the max heap sizes before starting maven. When I tried to use the tag to set perm size to 256, I did a jstat -gccapacity maven-pid after starting the app and saw that my max perm gen was still just 82 kb – rzrelyea May 13 '13 at 17:01
  • 19
    adding this to pom.xml won't work, it's too late. You have to pass such parameters directly to the JVM, in the Run -> Run configurations...-> JRE tab -> VM Arguments. You can check what's going on with VisualVM (simple profiler embedded with your Oracle JDK). – Vito Meuli Jun 06 '13 at 07:43
  • 3
    I agree with *rzrelyea* that this does not work and that the expectations for it to work are low at best. Since it is undocumented, it looks a lot as if *Rene Herget* just dreamt this up. Unless further information comes available I'm voting this one down! – Sander Verhagen Jul 13 '14 at 05:50
  • 1
    I have tried this as a solution to pass other JVM options and found that the options appeared to not take effect in tomcat when passed this way. Moreover, I found that the same options did take effect via MAVEN_OPTS thus inferring that this method does not work. For me this answer was a bit of a bum steer. – Nick Weedon Sep 26 '14 at 15:07
  • Of course this is not changing the memory for the Maven process, but for the Tomcat process started by Maven. That's what the original poster asked: How to increase memory of tomcat7 maven plugin! – Sebi Oct 06 '14 at 17:28
  • 2
    @Sebi I just tested this, and it had no effect on the tomcat instance started, just as everyone else here has said. If you got it working, you're doing something else than the rest of us... – Epcylon Jan 13 '15 at 10:05
  • 3
    Does not work at all and should not be the accepted answer. As the documentation says and the tag suggests you can set **system properties** that way, but not **environment variables** – Torben Knerr Jun 01 '15 at 14:02
  • this setting not work for the tomcat7 maven plugin.i solved my problem by set a MAVEN_OPTS like @Lennart Kramer 's answer – navee Aug 05 '16 at 03:01
  • this setting not work for the tomcat7 maven plugin.i solved my problem by set a MAVEN_OPTS like @Lennart Kramer 's answer – navee Aug 05 '16 at 03:01
0

This one worked for me:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>...</version>
    <configuration>
        <container>...</container>
        <configuration>
            <type>standalone</type>
            <home>...</home>
            <properties>
                <cargo.jvmargs>-Xmx4096m</cargo.jvmargs>
            </properties>
        </configuration>
        <deployables>...</deployables>
    </configuration>
</plugin>

It starts up my tomcat8 in a new JVM with argument "-Xmx4096m".

Hombre
  • 31
  • 4