Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify the path of a JAR in an ant buildfile?

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.

Is there a way I can specify the path of the JAR in the ant build XML itself?

like image 229
Ravi Avatar asked Feb 24 '11 12:02

Ravi


1 Answers

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>

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.

like image 155
Ravi Avatar answered Oct 11 '22 15:10

Ravi