How to control VM arguments for maven-jetty-plugin?

JavaJettyMaven 2Maven Jetty-Plugin

Java Problem Overview


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 command.

Java Solutions


Solution 1 - Java

The enviroment variable MAVEN_OPTS is the answer. The string content of MAVEN_OPTS is passed to JVM (java.exe).

  • Linux: in shell type export MAVEN_OPTS=....
  • Windows: in shell (cmd.exe) type set MAVEN_OPTS=...

For example: on Windows set MAVEN_OPTS="-Xmx1024m" sets the heap size of the Maven process to 1024mb.

Update (01.04.2013): Pass it directly to Jetty.

Matthew Farwell (please upvote his answer to give him credit) comes with the solution of using a forked JVM process to run Jetty which is a new feature of the Jetty plugin. This is a better solution as the former runs inside same JVM process as Maven (thus shares memory).

Solution 2 - Java

With more recent versions of the maven-jetty-plugin, you can use mvn:run-forked. The option jvmArgs will allow you to set -Xmx etc.

For more information, see: jetty:run-forked : Running an unassembled webapp in a separate jvm.

I think the original issue was Starting Jetty in separate JVM.

Solution 3 - Java

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).

Solution 4 - Java

To specify vm arguments via the command line (as originally asked) you can do the following:

mvn clean install -DargLine="-Xmx1524m" 

Solution 5 - Java

The <jvmArgs> param mentioned here : Maven jetty plugin didn't work for me .

Maven version : Apache Maven 3.0.3

Jetty Maven plugin version : jetty-maven-plugin:8.1.10.v20130312

This worked :

MAVEN_OPTS='-Xmx4096m -Xms4096m'
export MAVEN_OPTS
mvn jetty:run &

Solution 6 - Java

On Linux/Unix

export MAVEN_OPTS="-Xmx256m" && mvn clean install jetty:run

will do the trick

Solution 7 - Java

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>

Solution 8 - Java

you can use to pass -Xmx argument like;

<plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version></version>
            <configuration>
                <jvmArgs>-Xmx -Xms -XX:PermSize= -XX:MaxPermSize= -XX:+HeapDumpOnOutOfMemoryError</jvmArgs>
                <scanIntervalSeconds>1</scanIntervalSeconds>
                <stopKey>stop-jetty</stopKey>
                <stopPort>9999</stopPort>
                <systemProperties>
                    <systemProperty>
                        <name>jetty.port</name>
                        <value>9090</value>
                    </systemProperty>
                    <systemProperty>
                        <name>spring.profiles.active</name>
                        <value></value>
                    </systemProperty>
                </systemProperties>

                <webApp>
                    <contextPath>/</contextPath>
                </webApp>
            </configuration>
        </plugin>

Solution 9 - Java

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%

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichal BernhardView Question on Stackoverflow
Solution 1 - JavaMichal BernhardView Answer on Stackoverflow
Solution 2 - JavaMatthew FarwellView Answer on Stackoverflow
Solution 3 - JavadanbenView Answer on Stackoverflow
Solution 4 - JavaChris RitchieView Answer on Stackoverflow
Solution 5 - JavaBinita BharatiView Answer on Stackoverflow
Solution 6 - JavaGonzalo Gómez GarcíaView Answer on Stackoverflow
Solution 7 - JavadoredsonView Answer on Stackoverflow
Solution 8 - Javauser2663609View Answer on Stackoverflow
Solution 9 - JavaGrimView Answer on Stackoverflow