nacos启动“找不到或无法加载主类 ”java.lang.ClassNotFoundException:
从官网下载的Nacos编译之后的包,启动时报如下错误:
错误:找不到或无法加载主类
原因:java.lang.ClassNotFoundException:
导致该问题的主要原因是Nacos对JDK 11不兼容导致的。因此,最直接的方案是换JDK,比如采用JDK 8等。
如果无法换JDK,则可修改启动脚本:
Version: 2.0.3 jdk version: 11.0.10 os: mac 11.1 How to Reproduce: Modify the startup script(startup.sh) The original script is: nohup "$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 & Try the modified script is : nohup ${JAVA} ${JAVA_OPT_EXT_FIX} ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 & others: If the build command is mvn clean compile && mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U.and the parameter path("${JAVA_OPT} -jar ${BASE_DIR}/target/${SERVER}.jar") in the script is inconsistent with the actual path,and The actual build path is ("${JAVA_OPT} -jar ${BASE_DIR}/target/${PROJECT_VERSION}/target/${SERVER}.jar"). the script can be modified or the jar location can be moved.
或:
Under bin / startup.sh JAVA_ OPT_ EXT_ FIX configuration will cause JDK11 error please replace bin / startup.sh x JAVA_ OPT_ EXT_ FIX="-Djava.ext.dirs=${JAVA_ HOME}/jre/lib/ext:${JAVA_ HOME}/lib/ext" √ JAVA_ OPT="${JAVA_ OPT} -Djava.ext.dirs=${JAVA_ HOME}/jre/lib/ext:${JAVA_ HOME}/lib/ext" x echo "$JAVA $JAVA_ OPT_ EXT_ FIX ${JAVA_ OPT}" √ echo "$JAVA ${JAVA_ OPT}" x echo "$JAVA $JAVA_ OPT_ EXT_ FIX ${JAVA_ OPT}" > ${BASE_ DIR}/logs/start.out 2>&1 & x nohup "$JAVA" "$JAVA_ OPT_ EXT_ FIX" ${JAVA_ OPT} nacos.nacos >> ${BASE_ DIR}/logs/start.out 2>&1 & √ echo "$JAVA ${JAVA_ OPT}" > ${BASE_ DIR}/logs/start.out 2>&1 & √ nohup $JAVA ${JAVA_ OPT} nacos.nacos >> ${BASE_ DIR}/logs/start.out 2>&1 &
关注公众号:程序新视界,一个让你软实力、硬技术同步提升的平台
除非注明,否则均为程序新视界原创文章,转载必须以链接形式标明本文链接
本文链接:https://choupangxia.com/2021/08/17/nacos-java-lang-classnotfoundexception/