Home > Blockchain >  Java 17 with Maven Wrapper results in Unrecognized VM option 'MaxPermSize=512m'
Java 17 with Maven Wrapper results in Unrecognized VM option 'MaxPermSize=512m'

Time:10-03

I use OpenJDK 17 with Maven Wrapper 3.8.2 from Spring Initializr (Maven project, JAR packaging, Java 17, Spring Boot 2.6.0). No additional dependencies.

user@DESKTOP-U2OU5HG MINGW64 /c/Projects/my-project (master)
$ java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment (build 17 35-2724)
OpenJDK 64-Bit Server VM (build 17 35-2724, mixed mode, sharing)

Upon running any of ./mvnw.cmd -version or ./mvnw.cmd clean install, I always get the following message:

Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Switching to OpenJDK 16.0.2 resolves the issue, however, I need to work with Java 17.

How to get it run? There is nowhere MaxPermSize=512m set.

CodePudding user response:

Indeed -XX:MaxPermSize=size is labeled as follows according to Java® Development Kit Version 16/17 Tool Specifications (see the links):

The Maven Wrapper in the mvnw.cmd script, however, aside from the required JAVA_HOME uses also a bunch of optional environment variables such as M2_HOME and these starting with MAVEN_ prefix.

The important one is MAVEN_OPTS where such a removed Java option can appear causing the inability to start the JVM on the newer version. In my case, I had something like:

-Xmx4g -XX:MaxPermSize=512m -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all

The solution is either to remove the option from the environment variables or add this line to Maven Wrapper script to override the MAVEN_OPTS value:

  • In the minimal form: MAVEN_OPTS=
  • Related