在 java 11 中启用了 hazelcast-kubernetes 集群 ClassNotFoundException

问题描述

我在 Java 11 中为我的应用程序启用了 hazelcast-kubernetes,但是当我尝试部署它时,我收到以下警告

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

为了解决这个问题,我在我的 deployment.yaml 中添加了 java args 命令,如此 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 \\"]

当我尝试在集群中部署 Pod 时,出现以下错误:-

Error: Could not find or load main class  --add-modules java.se \
Caused by: java.lang.classNotFoundException:  --add-modules java.se \

解决方法

看起来你的论点有问题。

变化:

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 \\"]

致:

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