Java – Maven doesn’t seem to pass parameters to the JVM

Maven doesn’t seem to pass parameters to the JVM… here is a solution to the problem.

Maven doesn’t seem to pass parameters to the JVM

I’m trying to compile an Android app that relies on OrmLite, but no matter what I do, I’m still getting the OutOfMemory error.

I

think the reason Maven doesn’t pass any parameters about heap size is that I can only see the following in its output:

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar/Users/mikhail.borozdin/android-sdk-macosx/platform-tools/lib/dx.jar – -dex –output=/ Users/mikhail.borozdin/Documents/workspace/AndroidOrmLiteTest/target/classes.dex

How do I try to pass parameters to the JVM?

  • Export MAVEN_OPTS=-XMX2048M
  • mvn -X install -DargLine=”-Xmx2048m”
  • Set up my plugin in pom.xml
  • Set up my plugin in pom.xml

None of this works.

Solution

If the project you’re building is using android-maven-plugin, you want to set it dex mojo configuration in the maven pom.xml file, for example:

<dex>
  <jvmArguments>
    <jvmArgument>-Xms256m</jvmArgument>
    <jvmArgument>-Xmx512m</jvmArgument>
  </jvmArguments>
</dex>

Here is an example from a full pom.xml file:

https://github.com/rtyley/agit/blob/a014c970/pom.xml#L116-121

Note that the specific XML used for dex configuration was considerably evolved before the release of android-maven-plugin version 3.0.0 (it has a lot of other important improvements) – I recommend making sure that you are using this version and that the configuration definitely uses <dex> nodes.

android-maven-plugin will use a 1GB heap by default in versions after v3.0.0 ( Not published at the time of writing).

Related Problems and Solutions