Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to specify the location of a local jsch.jar from within build.xml?

Tags:

java

scp

ant

build.xml contains <scp> and <sshexec> tasks, so I provide jsch.jar and other libraries in the same directory together with build.xml.

The following taskdef:

<taskdef name="scp"
    classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"
    classpath="WebContent/WEB-INF/lib/jsch-0.1.43.jar" />

throws an error

A class needed by class org.apache.tools.ant.taskdefs.optional.ssh.Scp
cannot be found: com/jcraft/jsch/UserInfo

I cannot modify the standard Ant installation (e.g. put jsch.jar in ant lib directory, or remove ant-jsch.jar), or add command-line flags, or modify system environment variables, etc.: the script has to run with default Ant on different systems.

I'm actually reposting the question originally asked here: http://ant.1045680.n5.nabble.com/specifying-location-of-an-external-library-within-build-xml-td1344969.html

but could not get the answer about classloader to work.

like image 304
Tomasz Avatar asked Sep 16 '10 12:09

Tomasz


1 Answers

I was able to solve this issue following post from here https://stackoverflow.com/a/858744/3499805 and then

<taskdef resource="net/jtools/classloadertask/antlib.xml" classpath="${basedir}/ant-lib/ant-classloadertask.jar" />
<classloader loader="system" classpath="${basedir}/ant-lib/jsch-0.1.54.jar"/>
like image 135
user3499805 Avatar answered Oct 18 '22 03:10

user3499805