Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert MAVEN_OPTS in the POM.xml

Tags:

maven

pom.xml

I must increase java heap space to compile my project. The only way I found is modify mvn.bat and set:

set MAVEN_OPTS=-XX:PermSize=256m -XX:MaxPermSize=256m -Xms1300M -Xmx1300M

than all colleagues must change the file localy. I want keep all inside my project, not localy. Can I insert in the POM.xml or other file?

like image 449
Spirit - Stop War in Ukraine Avatar asked May 15 '14 08:05

Spirit - Stop War in Ukraine


People also ask

What is MAVEN_OPTS =- Xms256m?

MAVEN_OPTS environment variable:This variable contains parameters used to start up the JVM running Maven and can be used to supply additional options to it. E.g. JVM memory settings could be defined with the value -Xms256m -Xmx512m .

What is the use of MAVEN_OPTS?

MAVEN_OPTS is an environment variable used by the shell scripts that launch the Java Virtual Machine (JVM) that runs Maven. Using MAVEN_OPTS you can pass options to the JVM when it's launched.


Video Answer


1 Answers

Setting MAVEN_OPTS usually provides arguments to the JVM running the build, and these are passed down to the compiler because it runs inline. You have probably already noted that the maven-surefire-plugin used for test usually fork a separate process so passing options to the plugin is bound inside the pom.xml.

What if you fork the compilation process also and add the flags there, such as the below example.

Notice the fork and the compiler args

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <fork>true</fork>
          <meminitial>128m</meminitial>
          <maxmem>512m</maxmem>
          <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>
like image 138
Niels Bech Nielsen Avatar answered Oct 28 '22 00:10

Niels Bech Nielsen