我正在尝试运行一个使用 dcm 的 Gradle 项目 (https://github.com/vmware/declarative-cluster-management)。
我调用了“./gradlew build”,这是成功的,然后“java -jar build/libs/project.jar”来运行主类,为此我收到了此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jooq/impl/DSL
at com.rebalancer.LoadBalance.setup(LoadBalance.java:92)
at com.rebalancer.LoadBalance.<init>(LoadBalance.java:43)
at com.rebalancer.RebalancerExperiment.main(RebalancerExperiment.java:20)
Caused by: java.lang.ClassNotFoundException: org.jooq.impl.DSL
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 3 more
我尝试确保正确设置了依赖项。以下是我的build.gradle:
plugins {
id 'java'
}
jar {
manifest {
attributes 'Main-Class': 'com.rebalancer.RebalancerExperiment'
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.vmware.dcm:dcm:0.15.0'
implementation "org.jooq:jooq:3.13.1"
implementation "org.jooq:jooq-meta:3.13.1"
implementation "com.google.guava:guava:${guavaVersion}"
implementation "org.junit.jupiter:junit-jupiter:${junitJupiterVersion}"
implementation "org.junit-pioneer:junit-pioneer:${junitPioneerVersion}"
}
DCM项目也使用jooq库,因此我通过使用“./gradlew依赖项”确保两个版本使用相同的版本(并且我避免版本冲突)。这些是运行时的依赖项:
+--- com.vmware.dcm:dcm:0.15.0
| +--- org.apache.logging.log4j:log4j-api:{strictly [2.17.1, 3[; prefer 2.17.1} -> 2.17.1
| +--- org.apache.logging.log4j:log4j-core:{strictly [2.17.1, 3[; prefer 2.17.1} -> 2.17.1
| | \--- org.apache.logging.log4j:log4j-api:2.17.1
| +--- org.apache.logging.log4j:log4j-slf4j-impl:{strictly [2.17.1, 3[; prefer 2.17.1} -> 2.17.1
| | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.33
| | +--- org.apache.logging.log4j:log4j-api:2.17.1
| | \--- org.apache.logging.log4j:log4j-core:2.17.1 (*)
| +--- org.jooq:jooq:3.13.1
| | +--- org.reactivestreams:reactive-streams:1.0.2
| | \--- javax.xml.bind:jaxb-api:2.3.1
| | \--- javax.activation:javax.activation-api:1.2.0
| +--- org.jooq:jooq-meta:3.13.1
| | \--- org.jooq:jooq:3.13.1 (*)
| +--- com.google.guava:guava:29.0-jre
| | +--- com.google.guava:failureaccess:1.0.1
| | +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
| | +--- com.google.code.findbugs:jsr305:3.0.2
| | +--- org.checkerframework:checker-qual:2.11.1 -> 3.10.0
| | +--- com.google.errorprone:error_prone_annotations:2.3.4 -> 2.5.1
| | \--- com.google.j2objc:j2objc-annotations:1.3
| +--- org.apache.calcite:calcite-core:1.30.0
| | +--- org.apache.calcite:calcite-linq4j:1.30.0
| | | +--- org.apiguardian:apiguardian-api:1.1.0
| | | +--- org.checkerframework:checker-qual:3.10.0
| | | \--- org.apache.calcite.avatica:avatica-core:1.20.0
| | | +--- org.apache.calcite.avatica:avatica-metrics:1.20.0
| | | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.33
| | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.33
| | +--- com.esri.geometry:esri-geometry-api:2.2.0
| | +--- com.google.errorprone:error_prone_annotations:2.5.1
| | +--- org.apache.calcite.avatica:avatica-core:1.20.0 (*)
| | +--- org.apiguardian:apiguardian-api:1.1.0
| | +--- org.checkerframework:checker-qual:3.10.0
| | +--- org.slf4j:slf4j-api:1.7.33
| | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.10.0
| | +--- com.google.uzaygezen:uzaygezen-core:0.2
| | | \--- org.apache.commons:commons-lang3:3.1 -> 3.8
| | +--- com.jayway.jsonpath:json-path:2.7.0
| | | \--- org.slf4j:slf4j-api:1.7.33
| | +--- commons-codec:commons-codec:1.13
| | +--- net.hydromatic:aggdesigner-algorithm:6.0
| | | +--- commons-lang:commons-lang:2.4
| | | \--- commons-logging:commons-logging:1.1.3 -> 1.2
| | +--- org.apache.commons:commons-dbcp2:2.6.0
| | | +--- org.apache.commons:commons-pool2:2.6.1
| | | \--- commons-logging:commons-logging:1.2
| | +--- org.apache.commons:commons-lang3:3.8
| | \--- commons-io:commons-io:2.11.0
| +--- org.freemarker:freemarker:2.3.31
| +--- com.facebook.presto:presto-parser:0.238.2
| | +--- javax.inject:javax.inject:1
| | +--- io.airlift:slice:0.38
| | | \--- org.openjdk.jol:jol-core:0.2
| | +--- org.antlr:antlr4-runtime:4.7.1
| | \--- com.facebook.airlift:log:0.191
| +--- com.squareup:javapoet:1.11.1
| +--- com.google.ortools:ortools-java:9.1.9490
| | +--- com.google.ortools:ortools-linux-x86-64:9.1.9490
| | +--- com.google.ortools:ortools-darwin-x86-64:9.1.9490
| | +--- com.google.ortools:ortools-win32-x86-64:9.1.9490
| | +--- net.java.dev.jna:jna-platform:5.8.0
| | | \--- net.java.dev.jna:jna:5.8.0
| | \--- com.google.protobuf:protobuf-java:3.18.0
| \--- com.google.protobuf:protobuf-java:3.15.0 -> 3.18.0
+--- org.jooq:jooq:3.13.1 (*)
+--- org.jooq:jooq-meta:3.13.1 (*)
+--- com.google.guava:guava:29.0-jre (*)
+--- org.junit.jupiter:junit-jupiter:5.7.2
| +--- org.junit:junit-bom:5.7.2
| | +--- org.junit.jupiter:junit-jupiter:5.7.2 (c)
| | +--- org.junit.jupiter:junit-jupiter-api:5.7.2 (c)
| | +--- org.junit.jupiter:junit-jupiter-engine:5.7.2 (c)
| | +--- org.junit.jupiter:junit-jupiter-params:5.7.2 (c)
| | +--- org.junit.platform:junit-platform-commons:1.7.2 (c)
| | +--- org.junit.platform:junit-platform-launcher:1.7.2 (c)
| | \--- org.junit.platform:junit-platform-engine:1.7.2 (c)
| +--- org.junit.jupiter:junit-jupiter-api:5.7.2
| | +--- org.junit:junit-bom:5.7.2 (*)
| | +--- org.apiguardian:apiguardian-api:1.1.0
| | +--- org.opentest4j:opentest4j:1.2.0
| | \--- org.junit.platform:junit-platform-commons:1.7.2
| | +--- org.junit:junit-bom:5.7.2 (*)
| | \--- org.apiguardian:apiguardian-api:1.1.0
| +--- org.junit.jupiter:junit-jupiter-params:5.7.2
| | +--- org.junit:junit-bom:5.7.2 (*)
| | +--- org.apiguardian:apiguardian-api:1.1.0
| | \--- org.junit.jupiter:junit-jupiter-api:5.7.2 (*)
| \--- org.junit.jupiter:junit-jupiter-engine:5.7.2
| +--- org.junit:junit-bom:5.7.2 (*)
| +--- org.apiguardian:apiguardian-api:1.1.0
| +--- org.junit.platform:junit-platform-engine:1.7.2
| | +--- org.junit:junit-bom:5.7.2 (*)
| | +--- org.apiguardian:apiguardian-api:1.1.0
| | +--- org.opentest4j:opentest4j:1.2.0
| | \--- org.junit.platform:junit-platform-commons:1.7.2 (*)
| \--- org.junit.jupiter:junit-jupiter-api:5.7.2 (*)
\--- org.junit-pioneer:junit-pioneer:1.4.2
+--- org.junit:junit-bom:5.7.1 -> 5.7.2 (*)
+--- org.junit.jupiter:junit-jupiter-api -> 5.7.2 (*)
+--- org.junit.jupiter:junit-jupiter-params -> 5.7.2 (*)
+--- org.junit.platform:junit-platform-commons -> 1.7.2 (*)
\--- org.junit.platform:junit-platform-launcher -> 1.7.2
+--- org.junit:junit-bom:5.7.2 (*)
+--- org.apiguardian:apiguardian-api:1.1.0
\--- org.junit.platform:junit-platform-engine:1.7.2 (*)
我调用了(...)“java -jar build/libs/project.jar”
那是你的问题。您不仅必须提供自己的代码,还必须提供包含您使用的所有依赖项的类路径。这些并没有神奇地包含在内。如果您使用 Gradle 启动应用程序,则无需手动调用
java
,它会自动为您执行此操作。