debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

参考:https://*.com/questions/57363051/exception-in-thread-main-java-lang-noclassdeffounderror-com-codahale-metrics

zookeeper 源码地址:https://github.com/apache/zookeeper.git

clone 到本地后

 

通过 zkServer.cmd 的 

call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*

找到 入口:QuorumPeerMain

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

 

1. 修改配置文件

(1)zoo_sample.cfg 改名为 zoo.cfg

(2)修改  dataDir 为 dataDir=/Users/kevin/Documents/workspace/ideaworkspace/zookeeper-release-3.7.0/data

 

2. 引入以下依赖 (如果 zookeeper-server 的 pom.xml 中没有的话),但要将 metrics-core 的  <scope>provided</scope> 注释掉

  <dependency>
      <groupId>commons-cli</groupId>
      <artifactId>commons-cli</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
       <groupId>io.dropwizard.metrics</groupId>
       <artifactId>metrics-core</artifactId>
       <scope>provided</scope>
    </dependency>

     <dependency>
      <groupId>org.xerial.snappy</groupId>
      <artifactId>snappy-java</artifactId>
      <scope>provided</scope>
    </dependency>
    
      <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlet</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-client</artifactId>
      <scope>provided</scope>
    </dependency>

 

3. 编译 zookeeper-jute 模块 并标记 target 中 generated-sources 中的 java 为 Generated Sources Boot

防止出现 ACL、Id 缺失的错误

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

 

 

4. 编译 zookeeper-server 并标记 target 中 generated-sources 中的 java 为 Generated Sources Boot

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

5.  debug 方式运行  QuorumPeerMain 中的 main 方法,在执行 ZooKeeperServerMain 类中 的 runFromConfig 方法的  ServerMetrics.metricsProviderInitialized(metricsProvider); 一行时,报 Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/Reservoir

原因:(1)2 中 metrics-core 的  <scope>provided</scope> 未注释掉 

   (2)缺少 metrics-graphite 依赖

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

解决方法:

参考 * 上 

Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/Reservoir 

这个问题的回答

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

 

 

 查看 zookeeper-server 的 pom.xml 中 metrics-core 的版本:

  <dependency>
       <groupId>io.dropwizard.metrics</groupId>
       <artifactId>metrics-core</artifactId>
<!--       <scope>provided</scope>-->
    </dependency>

 

 

 

 debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

 

 

版本为 :4.1.12.1

因此 引入 4.1.12.1 版本的 metrics-graphite 依赖:

    <dependency>
      <groupId>io.dropwizard.metrics</groupId>
      <artifactId>metrics-graphite</artifactId>
      <version>4.1.12.1</version>
    </dependency>

 

再次  compile  zookeeper-server 模块

 

6. 编辑启动配置,配置启动参数即 配置文件位置

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

 

 

 

 

 debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

填入 zoo.cfg 位置:

debug zookeeper 源码时,报 :Exception in thread "main" java.lang.NoClassDefFoundError: com/coda

 

即可运行成功

上一篇:服务监控 | 彻底搞懂Dropwizard Metrics一篇就够了


下一篇:DB2 错误信息码