JDK14 can't run "java --add-opens"
Asked Answered
E

3

9

I'm doing a small project to learn swagger-codegen. When I'm executing "mvn clean install" the next errors appear:

Unable to make public boolean java.util.Collections$EmptyMap.isEmpty() accessible: module java.base does not "opens java.util" to unnamed module @1e1b061

and then

Failed to execute goal io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.18:generate (default) on project swgtst-api: Code generation failed. See above for the full exception.

When i'm trying to solve it with java --add-opens=java.base/java.util=ALL-UNNAMED as written here https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-2F61F3A9-0979-46A4-8B49-325BA0EE8B66 Nothing happens, just java help is shown.

For sure the last command has problem with syntax, but I have no Idea what exactly... What am I doing wrong?

Egghead answered 15/4, 2021 at 15:50 Comment(0)
G
2

That option doesn't do anything on its own, but rather it modifies the way that invocation of Java will run. You still need to add that option to the java that is invoked when you run mvn.

One way to do that, is to add the option to the Maven files (someone else can help with that or you can search for how to set Java options in Maven files).

I ran into a similar situation and instead used _JAVA_OPTIONS to pass it through. You may be able to do something similar by prefixing your invocation of mvn with _JAVA_OPTIONS, though it is possible that Maven will override those and you'll have to modify the file as described above.

For reference, here is the command I used successfully:

_JAVA_OPTIONS="--add-opens=java.base/java.util=ALL-UNNAMED" swagger-codegen3 generate --lang python --input-spec spec.yaml
Graduated answered 30/6, 2021 at 5:4 Comment(0)
T
2

This error suggests that code generation plugin failed to access java.base and java.util package through reflection. JDK 16+ throws exception instead of warnings in these cases.

To execute codegen in a JDK 16+ environment you have to set following JVM option to allow access to these packages:

--add-opens=java.base/java.util=ALL-UNNAMED

To configure maven to use this option at runtime create a file jvm.config at path ${maven.projectBasedir}/.mvn and add above option into this file.

See here for more info:

--add-opens
jva.config file

Tragedian answered 13/7, 2022 at 20:12 Comment(0)
F
2

I had the same problem. I could workaround it by upgrading handlebars, a swagger-codegen dependency:

        <plugin>
            <groupId>io.swagger.codegen.v3</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>com.github.jknack</groupId>
                    <artifactId>handlebars</artifactId>
                    <version>4.3.0</version>
                </dependency>
            </dependencies>
            <executions>
             .
             .
             .
        </plugin>

Another option is to simply upgrade your swagger-code-maven-plugin to a version 3.0.0 or higher. More info here

Fivefold answered 13/10, 2022 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.