如何在 ant 构建文件中指定 JAR 的路径?

编程入门 行业动态 更新时间:2024-10-28 17:22:49
本文介绍了如何在 ant 构建文件中指定 JAR 的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在执行很多 scpsshexec 以及来自 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:关键词]

本文发布于:2023-04-20 12:47:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/983941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   文件   如何在   ant   JAR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!