从Grails控制器运行jcraft sshexec时得到NoClassDefFound

时间:2015-02-24 01:13:00

标签: grails ant jsch

我有一个groovy类,它正在调用AntBuilder.sshexec方法来执行远程命令。当我将这个Groovy类作为Java应用程序运行时,这很好用。但是,当我试图从控制器调用这个类/方法时,我得到了错误"由于java.lang.NoClassDefFoundError而无法创建类型sshexec:com / jcraft / jsch / UserInfo&# 34。

Groovy类:

package filemanager

import com.jcraft.jsch.*
import com.jcraft.jsch.ChannelSftp.*

class FileWork {
    String servName
    String servUser
    String servPassword
    String servFolder
    String localFolder
    int    servPort
    String fileName

    FileWork (String p_servName, String p_servUser, String p_servPassword, String p_servFolder, String p_localFolder, int p_servPort,String p_fileName) {
        println 'Exec constructor'
        this.servName = p_servName
        this.servUser = p_servUser
        this.servPassword = p_servPassword
        this.servFolder = p_servFolder
        this.localFolder = p_localFolder
        this.servPort = p_servPort
        this.fileName = p_fileName
    }
    .....
     String runRemoteCommand () {//(Session p_ses) {
         try {
         def result = ''
         def ant = new AntBuilder()
         ant.sshexec(
           host: servName,
           port: servPort,
           trust: true,
           username: servUser,
           password: servPassword,
           command: "unzip -o ${servFolder}${fileName} -d ${servFolder}",
           outputproperty: 'result',
           verbose: false
         )
         return result
         } catch (Exception e) {
         println 'This is filemanager.FileWork.runRemoteCommandException'
        e.printStackTrace();
         }
    }
}

控制器:

package filemanager

import com.jcraft.jsch.*
import com.jcraft.jsch.ChannelSftp.*

class ChooseToController {

    def index(params)         {
       params.max = Math.min(max ?: 10, 100)
        //render params
        //model:[destServ: DestServ, fileName:fileName]
     }

    def copyToRemote(params) {
        def destServ = DestServ.get(params.id)
        //FileWork fileWork = new FileWork (destServ.getDestServName(), destServ.getDestServUser(), destServ.getDestServPassword(), destServ.getDestServFolder(), "C:/tmp/", destServ.getDestServPort(), params.fileName)
        //Session ses = fileWork.connect()
        //fileWork.copyToRemoteServ(ses)
        //ses.disconnect()
        FileWork fileWork3 = new FileWork ("###########", "test", "Test123", "/home/test/IN/", "C:/tmp/", 22, "1.zip")
        String result = fileWork3.runRemoteCommand()
        println(result)
    }
}

依赖关系:

runtime "com.jcraft:jsch:0.1.51"
runtime "org.apache.ant:ant-jsch:1.8.1"

错误:

Could not create type sshexec due to java.lang.NoClassDefFoundError: com/jcraft/jsch/UserInfo
    at org.apache.tools.ant.AntTypeDefinition.createAndSet(AntTypeDefinition.java:278)
    at org.apache.tools.ant.AntTypeDefinition.icreate(AntTypeDefinition.java:219)
    at org.apache.tools.ant.AntTypeDefinition.create(AntTypeDefinition.java:206)fro.....

似乎并非所有类都可以从grails运行时上下文中看到...

0 个答案:

没有答案