2015-09-03 85 views
2

我使用Gradle构建了一个jar文件。它从“gradle run”中运行得很好,但是当我在Eclipse中运行它时(Run-> External Tools-> External Tools Configurations),我在其中一个Spring类上得到了NoClassDefFoundError。Jar文件可以从Gradle Run运行,但在Eclipse中运行时得到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文件,它没有依赖罐子,这就是为什么我在Eclipse中运行时,得到NoClassDefinition错误。我也尝试过在本地添加这些jar,但是这并不能解决问题,有人可以让我知道如何在Eclipse中运行这个jar吗?

dependencies { 
     compile fileTree(dir: 'lib', include: ['*.jar']) 
    } 

回答

1

当您添加依赖关系到你的build.gradle,你需要gradle eclipse通过命令行来获得新的JAR文件到在Eclipse项目配置的.classpath。如果您在执行此操作时正在运行eclipse,则需要刷新该项目,并且您会看到显示新的依赖关系。可能有一个用于eclipse的插件,或者可以让你在IDE中完成整个舞蹈的插件。

相关问题