15

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.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183

1 Answers1

34

Indeed -XX:MaxPermSize=size is labelled 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:

MAVEN_OPTS="-Xmx4g -XX:MaxPermSize=512m -Dfile.encoding=UTF-8"

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

MAVEN_OPTS=
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
  • 1
    for me (using Java 17), removing `-XX:MaxPermSize=512m` in pom.xml surefire configuration (`@{argLine} -Xmx1024m -XX:MaxPermSize=256m`), leaving me with `@{argLine} -Xmx1024m`, fixed my issues. – svassr Mar 31 '23 at 19:07
  • @svassr Yes, your case is luckily discoverable using the full-text search in the IDE. :) – Nikolas Charalambidis Apr 01 '23 at 12:39