2014-10-06 49 views
3

創建AntBuilder對象時,嘗試創建常規文件AntBuidler對象我得到異常下面無法在常規gradle這個

java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException 
at java.lang.Class.getDeclaredConstructors0(Native Method) 
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493) 
    at java.lang.Class.getDeclaredConstructors(Class.java:1901) 
    ..... 
    at at features.step_definitions.RewardEventsGeneration.GetEventXML(RewardEventsGeneration.groovy:40) 

在✽.ThenupdateLoyaltyInfo事​​件應該生成

我已經加入了相關的罐子我的lib文件夾,然後build.gradle

repositories { 
    mavenCentral() 
    flatDir { 
     dirs 'lib' 
    } 
} 

我的代碼中放置下面的代碼如下

def GetEventXML (userId, eventTypeIn) 
{ 
    def Host = "10.77.69.14" 
    def UserName = "system" 
    def Password = "password" 
    def Path = "/temp" 

    def eventTypeToLookFor = "eventType=\"$eventTypeIn\"" 
    def resultAsString = "" as String 

    def commandToRun = "grep -lH $userId $Path/*.xml | xargs grep -l '$eventTypeToLookFor' | cut -d: -f1" 
    def antEventCheck = new AntBuilder(); ********** Error line ****************** 


     antEventCheck.sshexec( trust:'true', 
       host:Host, 
       username:UserName, 
       password:Password, 
       command:commandToRun, 
       verbose:'true', 
       timeout:'10000', 
       failonerror:'false', 
       outputproperty:'eventCheckResult'); 

     resultAsString = antEventCheck.properties.eventCheckResult.toString() 

    return resultAsString 
} 

的build.gradle

dependencies { 
    ext.groovyVersion = "2.0.4" 
    ext.cucumberJvmVersion = "1.1.5" 
    ext.httpclientVersion = "4.2.1" 

    cucumberRuntime files("${jar.archivePath}") 

    compile ('com.jcraft:jsch:0.1.49') 

    compile('com.github.groovy-wslite:groovy-wslite:0.8.0') 
    groovy("org.codehaus.groovy:groovy-all:${groovyVersion}") 
    compile("org.apache.httpcomponents:httpmime:4.1.2") 
    compile("org.codehaus.groovy.modules.http-builder:http-builder:0.5.2") { 
     exclude group: "org.codehaus.groovy", module: "groovy" 
    } 
    compile("net.sf.json-lib:json-lib:2.4:jdk15") 
    compile("javax.mail:mail:1.4.5") 
    compile("org.apache.httpcomponents:httpclient:${httpclientVersion}") 
    compile("org.codehaus.geb:geb-core:0.7.2") { 
     exclude group: "org.codehaus.geb", module: "geb-implicit-assertions" 
    } 

    drivers.each { driver -> 
     testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$version.selenium" 
    } 

    compile("org.seleniumhq.selenium:selenium-support:2.25.0") 
    compile("log4j:log4j:1.2.17") 

    testCompile("junit:junit:4.10") 
    testCompile("info.cukes:cucumber-groovy:${cucumberJvmVersion}") 
    testCompile("info.cukes:cucumber-junit:${cucumberJvmVersion}") 
} 

感謝您的意見

+0

什麼的'dependencies'塊?在那裏聲明瞭Ant依賴關係嗎? – 2014-10-06 23:55:10

+0

@PeterNiederwieser我沒有把任何東西放在'dependencies'下。剛剛添加在'repositories'下的'build.gradle'文件中,就像我在'http://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to -build-gradle-file'我可以在這裏看到我的項目'lib'下的類文件'ant-1.7.0.jar - > \ org \ apache \ tools \ ant \ BuildException.class' – SMPH 2014-10-07 00:06:37

+0

'部分'build.gradle'文件的問題 – SMPH 2014-10-07 02:49:56

回答

1

以下工作完美

正如彼得的回答將flatDir不是要去足夠的規定。需要同樣添加到依賴以及

repositories { 
    mavenCentral() 
    flatDir { 
     dirs 'lib' 
    } 
} 


dependencies { 
    compile("ant:ant:1.7.0") 
} 

感謝彼得