问题描述
限时送ChatGPT账号..我正在执行很多 scp
和 sshexec
以及来自 ant 构建脚本的其他远程命令.如果 jsch.jar
不在 ant lib
目录中,这些命令将不起作用.为了使它工作,我将 JAR 复制到 ant lib
目录中,但这不是一个好的解决方案,因为其他任何想要运行脚本的人都必须做同样的事情.要从 Teamcity 运行 ant 目标,我们必须明确设置 lib 文件的路径.
I am executing lot of scp
and sshexec
and other remote commands from an ant build script. These commands don't work if jsch.jar
isn't in the ant lib
directory. To make it work, I copied the JAR into the ant lib
directory, but this is not a good solution, as anyone else wanting to run the script would have to do the same thing. To run the ant target from Teamcity, we will have to explicitly set the path of the lib file.
有没有办法在 ant build XML 中指定 JAR 的路径?
Is there a way I can specify the path of the JAR in the ant build XML itself?
推荐答案
感谢大家的回答.我设法让它与类加载器任务一起工作.这就是我所做的.
Thanks all for your answers. I am managed to get it work with classloader task. This is what I did.
<project basedir="." >
<property environment="env"/>
<taskdef resource="net/jtools/classloadertask/antlib.xml">
<classpath>
<fileset dir="${basedir}/lib" includes="ant-classloader*.jar"/>
</classpath>
</taskdef>
<!--Add JSCH jar to the classpath-->
<classloader loader="system">
<classpath>
<fileset dir="${basedir}/lib" includes="jsch*.jar"/>
</classpath>
</classloader>
<target name="Test">
<scp todir="user1:pass1@server1:/tmp" trust="true" >
<fileset dir="dir1">
<include name="test.txt" />
</fileset>
</scp>
</target>
</project>
正如你在这里看到的,我不需要为我的测试"目标提供任何依赖目标,它只是有效.它使用类加载器,将 jsch.jar 附加到系统类加载器.
As you can see here, I didn't have to give any dependant target for my "Test" target, it just works. It uses classloader, which appends jsch.jar to the system classloader.
这篇关于如何在 ant 构建文件中指定 JAR 的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论