作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在用 groovy 编写我的第一个自动化脚本,但遇到了障碍。在使用 AntBuilder 类运行 sshexec() 时,我遇到了以下错误:
: 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
到目前为止,我找到的最佳解决方案是使用
Grape.grab(group : "com.jcraft", module : "jsch", classLoader : this.class.classLoader.rootLoader)
Grape.grab(group:"ant", module:"ant-jsch", classLoader:this.class.classLoader.rootLoader)
为了加载所需的模块。但是,我想消除 Grape 从远程 Maven 存储库下载 jar 的延迟时间。
有没有办法下载和保存模块以供将来使用,也许在 JAVA_PATH 或类似的东西中?
最佳答案
使用 Grape 注解在运行时下载脚本依赖:
@Grapes([
@Grab(group='org.apache.ant', module='ant-jsch', version='1.8.3'),
@GrabConfig(systemClassLoader=true)
])
def ant = new AntBuilder()
ant.sshexec(host:"somehost", username:"yo", password:"dude", command:"ls")
如果您在防火墙后面,您还可以配置 Maven 存储库的位置:
@GrabResolver(name="my-repo", root="http://my.hostname/maven/repo")
最后的提示,groovy.grape.autoDownload 属性可用于控制 grape 是进行远程下载还是仅使用其缓存文件。
groovy -Dgroovy.grape.autoDownload=false myscript.groovy
关于java - 我可以避免使用 Grape 在 Groovy 中加载模块吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10536894/
我是一名优秀的程序员,十分优秀!