JVM Settings

The Simplest Case

If you don't use any extraJvmArguments nor JvmSettings at all like the following configuration:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        ...
        <configuration>
          <programs>
            <program>
              <mainClass>com.mycompany.app.App</mainClass>
              <id>app</id>
            </program>
          </programs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

The generated script (in this case Unix) will look like the following (license header removed):

#!/bin/sh
..
..
BASEDIR=`dirname $0`/..
BASEDIR=`(cd "$BASEDIR"; pwd)`



# OS specific support.  $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
case "`uname`" in
  CYGWIN*) cygwin=true ;;
  Darwin*) darwin=true
           if [ -z "$JAVA_VERSION" ] ; then
             JAVA_VERSION="CurrentJDK"
           else
             echo "Using Java version: $JAVA_VERSION"
           fi
           if [ -z "$JAVA_HOME" ] ; then
             JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
           fi
           ;;
esac

if [ -z "$JAVA_HOME" ] ; then
  if [ -r /etc/gentoo-release ] ; then
    JAVA_HOME=`java-config --jre-home`
  fi
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

# If a specific java binary isn't specified search for the standard 'java' binary
if [ -z "$JAVACMD" ] ; then
  if [ -n "$JAVA_HOME"  ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
      # IBM's JDK on AIX uses strange locations for the executables
      JAVACMD="$JAVA_HOME/jre/sh/java"
    else
      JAVACMD="$JAVA_HOME/bin/java"
    fi
  else
    JAVACMD=`which java`
  fi
fi

if [ ! -x "$JAVACMD" ] ; then
  echo "Error: JAVA_HOME is not defined correctly."
  echo "  We cannot execute $JAVACMD"
  exit 1
fi

if [ -z "$REPO" ]
then
  REPO="$BASEDIR"/repo
fi

CLASSPATH=$CLASSPATH_PREFIX:"$BASEDIR"/etc:"$REPO"/org/codehaus/mojo/appassembler-maven-plugin/...
EXTRA_JVM_ARGUMENTS=""

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  [ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
  [ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
  [ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
fi

exec "$JAVACMD" $JAVA_OPTS \
  $EXTRA_JVM_ARGUMENTS \
  -classpath "$CLASSPATH" \
  -Dapp.name="app" \
  -Dapp.pid="$$" \
  -Dapp.repo="$REPO" \
  -Dbasedir="$BASEDIR" \
  com.mycompany.app.App \
  "$@"

Global JvmArguments

If you need to setup memory settings for all of your generated scripts this can be achieved by using the extraJvmArguments.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        ...
        <configuration>
          <extraJvmArguments>-Xms16m</extraJvmArguments>
          <programs>
            <program>
              <mainClass>com.mycompany.app.App</mainClass>
              <id>app</id>
            </program>
          </programs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

extraJvmArguments with Place Holders

The settings of the extraJvmArguments is not limited to memory settings. You can use any kind of definition for the Jvm. It's more important that you can use place holders for the @REPO@ and for the @BASEDIR@. They are also given to the application by the following system properties by default.

  -Dapp.repo="$REPO" \
  -Dbasedir="$BASEDIR" \

The configuration to use extraJvmArguments looks like this:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        ...
        <configuration>
          <extraJvmArguments>-Dpar1=@BASEDIR@ -Dpar2=@REPO@</extraJvmArguments>
          <programs>
            <program>
              <mainClass>com.mycompany.app.App</mainClass>
              <id>app</id>
            </program>
          </programs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

JvmSettings

You can also use a complete JvmSettings with different parameters per program if you need to change that.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        ...
        <configuration>
          <programs>
            <program>
              <mainClass>com.mycompany.app.App</mainClass>
              <id>app</id>
              <jvmSettings>
                <initialMemorySize>20m</initialMemorySize>
                <maxMemorySize>256m</maxMemorySize>
                <maxStackSize>128m</maxStackSize>
                <systemProperties>
                  <systemProperty>anton=2345</systemProperty>
                  <systemProperty>berta="xaz"</systemProperty>
                </systemProperties>
                <extraArguments>
                  <extraArgument>-Dtest=false</extraArgument>
                  <extraArgument>-Dlog4j.properties=false</extraArgument>
                </extraArguments>
              </jvmSettings>
            </program>
          </programs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

The generated script contains now the parameters for the above information in the following manner:

...
EXTRA_JVM_ARGUMENTS="-Xms20m -Xmx256m -Xss128m -Dtest=false -Dlog4j.properties=false -Danton=2345 -Dberta="xaz""

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  [ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
  [ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
  [ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
fi

exec "$JAVACMD" $JAVA_OPTS \
  $EXTRA_JVM_ARGUMENTS \
  -classpath "$CLASSPATH" \
  -Dapp.name="app" \
  -Dapp.pid="$$" \
  -Dapp.repo="$REPO" \
  -Dbasedir="$BASEDIR" \
  com.mycompany.app.App \
  "$@"