在Grails forked JVM中使用ant sshexec()

时间:2014-01-13 19:19:12

标签: grails

使用Grails(版本2.3及更高版本)中包含的分叉JVM环境时,我遇到了一个问题。在没有分叉环境的情况下,一切都运行良好,我只是想了解导致事情在启用时停止正常工作的原因。我正在尝试通过Groovy的AntBuilder帮助程序类在远程服务器上执行命令。 sshexec()方法继续抛出错误 - 它无法找到sshexec所需的jar(我添加了依赖项)。

def ant = new AntBuilder()

try  {
    ant.sshexec(host: host, username: name, passphrase: pass, command: 'echo test', outputproperty: 'result')
}
catch(Exception e)  {
    throw new Exception("${ant.project.properties.'result'}")
}

我可以运行像ant.echo("hello")这样的东西,所以它似乎与sshexec有关。我正在使用BuildConfig.groovy中的默认设置:

grails.project.fork = [
    // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
    //  compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

    // configure settings for the test-app JVM, uses the daemon by default
    test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
    // configure settings for the run-app JVM
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the run-war JVM
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the Console UI JVM
    console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

如果我注释掉整个部分,消除分叉执行环境,一切正常。我知道分叉的JVM将构建类路径与运行时类路径隔离开来。这是否会阻止Grails拉入所需的依赖项?不确定为什么只注释grails.project.fork会修复所有问题。谢谢!

修改

这是我的依赖项:

dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
    runtime 'mysql:mysql-connector-java:5.1.24'

    runtime "com.jcraft:jsch:0.1.46"
    runtime "org.apache.ant:ant-jsch:1.8.2"
}

被抓住的例外:

Problem: failed to create task or type sshexec
Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -ANT_HOME/lib
        -the IDE Ant configuration dialogs
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem

0 个答案:

没有答案