hazelcast-kubernetes enabled cluster ClassNotFoundException in java 11

6/15/2021

I have enabled the hazelcast-kubernetes for my application in Java 11, but when I tried to deployed it I got below warning

09-Jun-2021 13:12:05.881 WARNING [main] com.hazelcast.instance.impl.HazelcastInstanceFactory.null Hazelcast is starting in a Java modular environment (Java 9 and newer) but without proper access to required Java packages. Use additional Java arguments to provide Hazelcast access to Java internal API. The internal API access is used to get the best performance results. Arguments to be used:
--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED

To resolve this I have added java args command in my deployment.yaml as mentioned in this link

      containers:
  - name: application
    image: docker-image
    command: ["java"]
    args: [" --add-modules java.se \\", " --add-exports java.base/jdk.internal.ref=ALL-UNNAMED \\", " --add-opens java.base/java.lang=ALL-UNNAMED \\", " --add-opens java.base/java.nio=ALL-UNNAMED \\", " --add-opens java.base/sun.nio.ch=ALL-UNNAMED \\", " --add-opens java.management/sun.management=ALL-UNNAMED \\", " --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED \\"]

When I tried to deployed the pod in my cluster I got below error:-

Error: Could not find or load main class  --add-modules java.se \
Caused by: java.lang.ClassNotFoundException:  --add-modules java.se \
-- ric
hazelcast
kubernetes

1 Answer

6/15/2021

Looks like there's an issue with your arguments.

Change:

args: [" --add-modules java.se \\", " --add-exports java.base/jdk.internal.ref=ALL-UNNAMED \\", " --add-opens java.base/java.lang=ALL-UNNAMED \\", " --add-opens java.base/java.nio=ALL-UNNAMED \\", " --add-opens java.base/sun.nio.ch=ALL-UNNAMED \\", " --add-opens java.management/sun.management=ALL-UNNAMED \\", " --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED \\"]

To:

args:
- --add-modules
- java.se
- --add-exports
- java.base/jdk.internal.ref=ALL-UNNAMED
- --add-opens
- java.base/java.lang=ALL-UNNAMED
- --add-opens
- java.base/java.nio=ALL-UNNAMED
- --add-opens
- java.base/sun.nio.ch=ALL-UNNAMED
- --add-opens
- java.management/sun.management=ALL-UNNAMED
- --add-opens
- jdk.management/com.sun.management.internal=ALL-UNNAMED
-- SYN
Source: StackOverflow