149

Possible Duplicate:
Maven Jetty plugin - how to control VM arguments?

In particular, I want to do something like this:

mvn -DjvmArgs="-Xmx2000m -Xms1000m -XX:PermSize=512m -XX:MaxPermSize=512m" jetty:run -Pmyprofile

Oh, and I would like to do this without having to modify the pom files or set any environment variables.. etc

Lii
  • 11,553
  • 8
  • 64
  • 88
Charlotte Tan
  • 2,452
  • 2
  • 20
  • 24
  • 8
    you have to set the MAVEN_OPTS enviroment variable, but that can be done on the command line: `MAVEN_OPTS="-Xmx2000m" mvn jetty:run` – Thilo Sep 21 '12 at 06:29
  • 10
    A little late, but you can use the -DargLine switch rather than using a global value. Full example [here](http://stackoverflow.com/questions/7527789/specifying-maven-memory-parameter-without-setting-maven-opts-environment-variabl/30441186#30441186) – Chris Ritchie May 25 '15 at 15:09
  • It's never too late! https://stackoverflow.com/a/68069089/5611377 – ssimm Sep 08 '21 at 14:51

1 Answers1

155

I think MAVEN_OPTS would be most appropriate for you. See here: http://maven.apache.org/configure.html

In Unix:

Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.

In Win, you need to set environment variable via the dialogue box

Add ... environment variable by opening up the system properties (WinKey + Pause),... In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.

nanosoft
  • 2,913
  • 4
  • 41
  • 61
Nishant
  • 54,584
  • 13
  • 112
  • 127
  • 2
    Is there a way to configure JVM argument in pom file? – nanosoft Jan 04 '17 at 13:05
  • 27
    @nanosoft No, as this would be to late (the JVM would have been started already). But [since Maven 3.3.1](https://maven.apache.org/docs/3.3.1/release-notes.html#JVM_and_Command_Line_Options) you can create a `.mvn/jvm.config` file with just the options in it. – Martin Höller Sep 28 '17 at 09:45
  • 2
    is it possible to give it as runtime args – Akhil Surapuram Dec 12 '19 at 06:18
  • 3
    `WinKey + Pause` how have I never learnt this before?! Very useful – Sina Madani May 11 '20 at 13:29
  • Tried this from a bash script but got: `MAVEN_OPTS: readonly variable` – Nom1fan Feb 08 '21 at 09:10
  • @MartinHöller `.mvn/jvm.config` only works during the build or when the fork count is zero (use `-DforkCount=0` in command line) beauce a forked VM might be used during the tests. – gouessej Aug 30 '21 at 19:33
  • I can't make maven use my system certificates on macOS: I'm adding "-Djavax.net.ssl.trustStoreType=KeychainStore" to .mvn/jvm.config without success. Option is from general JVM answer: https://stackoverflow.com/questions/14280578/how-to-set-up-java-vm-to-use-the-root-certificates-truststore-handled-by-mac-o – Ivan Dec 26 '22 at 13:22