cannot be found: com/jcraft/jsch/UserInfo - ant

I am trying to use the Ant <scp> task in my buildfile. It gives me an error every time I run the target:
cannot be found: com/jcraft/jsch/UserInfo
I have read some posts that talk about having this issue with Ant 1.7. Some of the posts are talking about removing the ant-jsch.jar files from the ant_home lib. Unfortunately I can't do that as the ant_home is common across lot of other projects and I can't remove or update any jar files from the lib directory.
Is there a way that I can solve this issue purely using Ant configuration?

ant-jsch.jar contains ssh related tasks developed by Apache Ant team, while jsch.jar contains the jsch library which is the dependency of those ssh tasks.
So do a little check: check if jsch.jar is in your $ANT_HOME/lib and also check if the jar contains UserInfo.class.
If one of above happens, download the latest version of jsch.jar and put it in $ANT_HOME/lib.
I am currently using Ant 1.8.4 with a jsch.jar downloaded last year without any problem.
Update:
Check this page first:
http://ant.apache.org/manual/install.html#optionalTasks
Please note that <scp> and other ssh tasks (the ant-jsch.jar) are included in the Ant binary distribution by default. You don't need to write <taskdef> to use <scp> because it is included in Ant's lib directory by default. I recommend you to put jsch.jar in that directory with the following points:
These ssh tasks don't support classpath def, that is to say, you can't define a <classpath> pointing to jsch.jar and then reference to it in an ssh task.
Also you can put jsch.jar in any directory included in your system's CLASSPATH environment variable, but it is not a good practice.
We usually put a task and its dependency in the same directory.

Related

class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec was not found

I have somewhat common problem with ant not being able to find the class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec. However, the common solutions don't work for me:
ensuring that the jsch.jar and ant-jsch.jar exists in the classpath
ensuring that there are not multiple different versions of the mentioned jars
ensuring that ant -diagnostics is infact seeing the jars
I have no idea what I should try out next. The output I get is the good 'ol:
build.xml: Problem: failed to create task or type sshexec
Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/opt/home/myname/.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.
My setup:
ant version: Apache Ant(TM) version 1.9.2 compiled on January 22 2014
ant-jsch version: 1.9.2
jsch version: 0.1.52
Ant diagnostics log can be found here: http://pastebin.com/q5AURxuk
As seen from the diagnostics log, the jars are there but ant reports:
sshexec : Not Available (the implementation class is not present)
I also extracted the jar file and ensured that the class is there.
Any ideas?
I've been hit by nearly the same problem, especially ant -diagnostics shows that sshexec task is "Not available".
On my system the solution was to install package "ant-optional" additionally (as I've already posted here: ANT can't find specific libraries)
Maybe this helps.
Regards
Came across a problem very similar to yours, problem with SCP rather than SSH but otherwise the same. Tou don't say if you compiled Ant yourself ot used a binary distribution, but or us it turned out to be a problem with the ant-jsch.jar not compiling properly. There was no suggestion of a problem on compile, but the jar was much smaller than expected, only 6k. We fixed the issue by using the ant-jsch.jar from the binary distribution, which is 48k. This was with ant-1.9.4 and ant-1.9.5, Java 1.8.0_45.

Jenkins Cannot find executable for ANT

I'm using the automatic installation option for Ant but still jenkins complains that it cannot find the executable. Am I missing something? I have given the path to the ant version we use. It has successfully downloaded and unpacked it on the server but it still complains it can't find the executable.
Did you install Ant? Is it in Jenkin's PATH? If not, Jenkins cannot use the default version of Ant.
However, if you go into the Jenkins configuration page, you can install various versions of Ant. For example, you may want to install the latest version of Ant, and Ant 1.5 for that one project that cannot use any version of Ant beyond 1.5:
When you define your project, you can select the version of Ant you want to use. When you select that you want to Invoke Ant as a build step, you are given a drop down menu of what version of Ant you want to use. The first is the Default which is the Ant version found in your PATH. However, if you've gone into Jenkins configuration and downloaded other versions of Ant, you can use one of those instead.
I think is more easy to you install ant manually , or you need check the jenkins log file for detailed errors
Found what I missed. I had to add the name of the directory it unpacks the ant file to in the
"Subdirectory of extracted archive" field. Forgot to mention we are using a fairly old version of ant. (1.7.0).

Worklight ant task using apache commons - where is this loaded from?

I'm trying to diagnose a failure in my ant file when it runs a Worklight task. I have a small ant file containing a simple reference to a Worklight task. This works correctly.
<target name="rawBuildApplication" >
<app-builder
applicationFolder="${applicationSource}"
environments="mobilewebapp"
nativeProjectPrefix="xxx"
outputFolder="${outputFolder}"/>
</target>
However when I invoke this ant file from a build control ant file (actually from the RTC build system) I get a failure (below), showing worklight failing to find an apache Java class. I assume there's some simple environmental difference, perhaps a classpath. It might help to figure it out if I knew where Worklight loaded the apache commons from. Right now I can't see anything in my environment in the case that works that points any apache Jar.
myAntFile.xml:146: java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.deleteQuietly(Ljava/io/File;)Z
at com.worklight.builder.util.BuilderUtils.<clinit>(BuilderUtils.java:672)
at com.worklight.builder.config.UserBuildConfiguration$Builder.<init>(UserBuildConfiguration.java:203)
at com.worklight.ant.builders.ApplicationBuilderTask.createBuildConfiguration(ApplicationBuilderTask.java:149)
at com.worklight.ant.builders.ApplicationBuilderTask.execute(ApplicationBuilderTask.java:80)
Edited: the cause is the use of -lib to add the RTC toolkit directory, exactly why this clashes and how to work around yet to be determined
Usually means you have version of the commons jar in your classpath, and its overriding the one packaged in the worklight-ant.jar. the apache commons files are inside the worklight-ant.jar file
Additional info from djna: I can confirm that when adding the Rational Team Concert (RTC) 3.0 toolkit to the ant classpath, either explicitly with -lib, or when selecting that option in the RTC Build definition some conflicting commons jars are added to the classpath. Worklight packages the classes it needs in its jar, but the -lib folder seems to take precedence.
My workaround is to replace the conflicting jars with later ones. I used these jars
commons-io-2.4.jar
commons-codec-1.8.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
I guess the other alternative is to upgrade to a newer RTC, but in our environment that's not currently possible.

"JUnitTask was not found" error (Hudson, Ant, JUnit)

I tried several ways to install ant and junit on the same server as hudson. I eventually downloaded the Ant source, installed the optional dependencies by using the included fetch.xml file, built the source code, and dropped junit-4.8.1.jar into the lib directory where the compiled ant code [that I just built] is. Then I set ANT_HOME to the ant root directory by using the "export ANT_HOME=/usr/share/ant" command. I also set a Hudson configuration variable of "ANT_HOME" with the same value (/usr/share/ant) and I also put a new file into the /etc/profile.d directory with the export ANT_HOME command as well. At this point I'm not sure what else to try, but Hudson still gives me the error:
BUILD FAILED /var/lib/hudson/jobs/MyProject/build.xml:31: Problem:
failed to create task or type junit Cause: the class
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
This looks like one of Ant's optional components. Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/var/lib/hudson/.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
I did, in fact, check /usr/share/ant/lib and the class "org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.class" is located in the ant-junit jar file as I confirmed by running the command: jar tfv ant-junit.jar | grep org.apache.tools.ant.taskdefs.optional.junit.JUnitTask
Can someone please tell me what to try, I am not sure where to go from here.
If you are on Ubuntu you can simply apt-get ant; I did that and linked to the junit jar within my project.
Cheers,
Neil
It turns out that hudson itself installs some version of Ant in one of its own libraries. I suppose that somehow caused a conflict because when I got rid of it, things worked. I think it is in /var/hudson or /var/hudson/lib. That path is added to the PATH environment variable during hudson installation. So your choice is either to add your own Ant install to the BEGINNING of the path, to delete hudson's version of Ant, or to delete that part of the PATH.

ANT job to invoke JDeveloper to create EAR file with specified deploy file

I was asked about the possibility of creating an ANT script that could be use to copy property files (associated to target environment), create an EAR file (perhaps using JDeveloper deploy file), and deploy that EAR file to target OC4J container.
I am asking if anyone ever successfully invoking JDeveloper automatically to create the EAR file by using specified 'deploy' file by using ANT? OR is it possible to by pass invoking JDeveloper at all. Is there any sample ANT code snippet to do so, or any information/hint that could be useful.
Thanks.
If you use ADF Business Components (BC) then you must use ojdeploy. Otherwise your BC will not get validated and your deployment will fail.
ojdeploy requires JDeveloper installation (ouch!) and will produce an EAR based on JDeveloper's deployment profiles .
(Although it's an old thread, I added something cos you never know.)
I would advise against using JDevelopers for creating an EAR file because I strongly believe that a build process must be autosufficient (i.e. as few external dependencies as possible).
Using Ant, you can simply use the Ear task (remember that the Ear task is a subtask of the Zip task, i.e. you can also use zipfileset inside the ear task).
I've never used OC4J but usually the deployment of an EAR file is just a matter of copying the file into the right directory (so a simple copy task would suffice).
Check out the ojdeploy command in the jdev\bin directory it will let you use JDeveloper's depoyment profiles from a command line.
I found that all the ant tasks used by jDeveloper are in the (default) directory: C:\Oracle\Middleware\jdeveloper\bin
I believe you can copy them to a build server and use them directly
They are the files it uses when you right click and select Deploy from the interface
You can build your own JDeveloper Deployment Profile Interpreter program and generate a Ant file from the Deployment Profile. I have done it before. Tim

Resources