我使用Gradle构建了一个jar文件。从#gradle run"开始运行良好,但是当我在Eclipse(Run-> External Tools-> External Tools Configurations)中运行它时,我在其中一个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错误的原因。我也通过在本地包含这些罐子来尝试这个,但是这并没有解决问题,有人能让我知道如何在Eclipse中运行吗?
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
}
答案 0 :(得分:1)
在向build.gradle添加依赖项时,需要从命令行gradle eclipse
将新JAR放入作为eclipse项目配置的.classpath中。如果您在执行此操作时运行了eclipse,则需要刷新项目并且您将看到新的依赖项出现。可能有一个用于eclipse的插件或允许你在IDE中完成整个舞蹈的东西。