我怎么可以指定在Ant构建一个JAR的路径? [英] How can I specify the path of a JAR in an ant buildfile?

查看:282
本文介绍了我怎么可以指定在Ant构建一个JAR的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个Ant构建脚本执行大量的SCP sshexec 和其他远程命令。如果 jsch.jar 不在蚂蚁 LIB 目录这些命令不起作用。为了使它工作,我复制的JAR到蚂蚁 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构建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆