我使用 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 错误的原因。我也通过在本地包含这些 jar 进行了尝试,但这并没有解决问题,有人可以让我知道如何在 Eclipse 中运行吗?
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
}
最佳答案
当您向 build.gradle 添加依赖项时,您需要从命令行 gradle eclipse
将新的 JAR 文件放入 .classpath,即 eclipse 项目配置。如果您在执行此操作时运行了 eclipse,则需要刷新项目,您将看到新的依赖项出现。可能有一个用于 eclipse 的插件或允许您在 IDE 中完成整个舞蹈的东西。
关于java - Jar 文件可以从 Gradle Run 运行,但在 Eclipse 中运行时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32387158/