![](/img/trans.png)
[英]NoClassDefFoundError when running exported JAR from Eclipse
[英]Jar file can run from Gradle Run but got NoClassDefFoundError when running within Eclipse
我使用 Gradle 构建了一个 jar 文件。 它从“gradle run”运行良好,但是当我从 Eclipse 中运行它时(运行->外部工具->外部工具配置),我在其中一个 Spring 类上遇到了 NoClassDefFoundError。
这是 build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'com.ii.mainClass'
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': 'com.ii.mainClass'
}
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile 'com.fasterxml.jackson.core:jackson-annotations:2.6.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.6.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.1'
compile 'org.springframework:spring-beans:4.2.0.RELEASE'
compile 'org.springframework:spring-context:4.2.0.RELEASE'
compile 'org.springframework:spring-core:4.2.0.RELEASE'
compile 'org.springframework:spring-expression:4.2.0.RELEASE'
compile 'org.springframework.xd:spring-xd-tuple:1.0.4.RELEASE'
}
我查看了 jar 文件,它没有依赖的 jar,这就是我在 Eclipse 中运行时出现 NoClassDefinition 错误的原因。 我也通过在本地包含这些 jars 来尝试这个,但这并不能解决问题,有人可以让我知道如何在 Eclipse 中运行它吗?
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
}
当您向 build.gradle 添加依赖项时,您需要gradle eclipse
以将新 JAR 放入 .classpath 中,即 eclipse 项目配置。 如果执行此操作时 eclipse 正在运行,则需要刷新项目,您将看到新的依赖项出现。 可能有一个 eclipse 插件或允许您在 IDE 中完成整个舞蹈的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.