Java 17 with Maven Wrapper results in Unrecognized VM option 'MaxPermSize=512m'
Asked Answered
U

3

26

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.

Unbalance answered 1/10, 2021 at 8:29 Comment(7)
It's possible that it came from .mvn/jvm.config.Finzer
It is set somewhere. Consider searching all your filesRunagate
Isn't this answers your question, #47112912 . After Java9 it seems MaxPermSize=512m is removed.Albatross
@JoachimSauer There is no .mvn/jvm.config file. Only wrapper folder.Unbalance
@ThorbjørnRavnAndersen: The only thing I switch is the home folder for Java 16 and 17 respectively. There is nothing set in my project as it is nearly empty and using downloaded Maven Wrapper.Unbalance
Yes. The newer JVM does not like a command option which comes from somewhere. You may want to single step your mvnw script.Runagate
@ManeeshaIndrachapa even Java 8 does not support this option.Undergrown
U
41

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=
Unbalance answered 1/10, 2021 at 9:2 Comment(2)
for me (using Java 17), removing -XX:MaxPermSize=512m in pom.xml surefire configuration (<argLine>@{argLine} -Xmx1024m -XX:MaxPermSize=256m</argLine>), leaving me with <argLine>@{argLine} -Xmx1024m</argLine>, fixed my issues.Gabon
@Gabon Yes, your case is luckily discoverable using the full-text search in the IDE. :)Unbalance
R
11

Use MaxMetaspaceSize in place of MaxPermSize and MetaspaceSize in place of PermSize in jdk17.

Refer to : https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html

Rung answered 22/9, 2023 at 11:6 Comment(0)
P
3

In addition to the above answers, You can add to the command line which starts your app a flag -XX:+IgnoreUnrecognizedVMOptions.

In this case, JVM will ignore all unrecognized flags.

Philipps answered 30/12, 2023 at 6:20 Comment(2)
This really helped me out when I had issues with testng.Lothar
I don't think it is a good practice to ignore unsupported flags, though thanks for this option.Unbalance

© 2022 - 2024 — McMap. All rights reserved.