Solution: “Could not load a dependent class” when using Ant through Eclipse
Problem
When running an optional Ant task (e.g. scp or sshexec) through the Eclipse Ant interface, you get an error similar to the one below.
BUILD FAILED
C:\Path\To\build.xml:45: Problem: failed to create task or type scp
Cause: Could not load a dependent class com/jcraft/jsch/UserInfo
It is not enough to have Ant's optional JARs
you need the JAR files that the optional tasks depend upon.
Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
-C:\Path\To\Ant\Home\lib
-C:\Path\To\User\Home\.ant\lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
However, you have found all required dependencies for the tasks you are trying to use and put them in one of the folders as specified.
Cause
Although you have added the right dependencies, Eclipse might not yet know of the file(s). If this is the case, you can see this by running Ant diagnostics (ant -diagnostics on the command line or the <diagnostics> ant task). You will see that the dependency is listed in the appropriate “lib jar listing” but is missing in the java.class.path system property.
Solution
Go to Window > Preferences > Ant > Runtime > Classpath, select “Ant Home Entries (default)” and click “Add External JARs…”. Select the required dependency or dependencies and accept. Now, the selected JAR files will be loaded to the class path and the optional ant task depending on them will work.
I tried this, adding the following jar files into “Ant Home Entries”, in order to run sshexec (these jars comes with standard JEE eclipse plugins):
org.eclipse.jsch.core_1.0.0.I20070426.jar org.eclipse.jsch.ui_1.0.1.r33x_20070709.jar
I am using Eclipse 3.3 (Europa) and am still geting the above error message (even after I restarted my eclipse workspace).
Any other thoughts.
thanks, Antro
Antro Peter - February 13th, 2008 at 18:45If the file missing according to your error message is the same as in my example (or another class from the
Henrik Jernevad - February 14th, 2008 at 10:50com.jcraft.jschpackage), the two jars you mention are not going to help. They contain Eclipse’s support functionality for the jsch library, not the library itself. You can download the files you need from http://www.jcraft.com/jsch/.Great tip!
It worked straight away.
Thanks! – Jerome.
Jerome - March 23rd, 2009 at 16:01Indeed a great blog. It solved my problem right away!! Thank you so much.
technewb - June 3rd, 2009 at 00:28Brilliant! Thank you.
James - August 6th, 2009 at 13:57Thanks for the tip. I had this problem when setting up my first build file that used the scp task and just encountered it again after setting up my dev environment on a new machine. Your straightforward solution made resolving this issue fast and simple.
Steve - October 20th, 2009 at 15:23Solution worked for me. Thanks !
vin - November 13th, 2009 at 00:10Thank you!! finally works!!
latara - March 18th, 2010 at 12:54Thanks, worked for me!
Brian - May 3rd, 2010 at 18:07