How to set VM arguments for Jetty run from maven-jetty-plugin?
For example, I need to pass -Xmx
arguments to Jetty run by the mvn jetty:run
There is no way using the commandline. But you could copy the mvn.cmd
/ mvn.sh
to mvnhp.cmd
and change the line
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
To
%MAVEN_JAVA_EXE% -Xmx1024m %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
The plugin allows you to specify jvmArgs like this:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<jvmArgs>-Xmx1024</jvmArgs>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webAppConfig>
<jettyEnvXml>jetty-env.xml</jettyEnvXml>
</webAppConfig>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run-exploded</goal>
</goals>
</execution>
</executions>
</plugin>
It seems like your current approach is correct - when running jetty through maven, jetty is a thread inside the maven process. So increasing maven's heap will increase jetty's heap.
How are you setting MAVEN_OPTS?
One example I found looks like this: MAVEN_OPTS='-Xmx256m -Xms10m' mvn clean jetty:run
Note that MAVEN_OPTS
is an environment variable here, and not passed to the JVM (who wouldn't know what to do with it).