Including -lib command line parameters in ant build.xml - ant

I have a build script that requires the -lib command line switch like so:
ant -lib lib/jsch-20101122.jar ....
This works fine, but I'd like to include that command line argument as part of my build.xml file and make my build cleaner.
I'd prefer not to include this jar in my ANT_HOME/bin directory.
Is there any way to do it?

I assume, that you want to use the scp-task (http://ant.apache.org/manual/Tasks/scp.html)
The official doc (http://ant.apache.org/manual/install.html#optionalTasks) for optional Tasks offers no real alternative (you may want to look at the CLASSPATH alternative, though).
The scp-task does not seem to have a classpath setting.

Related

Using Listeners&Loggers in build.xml

I want to use Listeners&Loggers in my script build.xml
I have seen the suggested method, but it is on cmd -logger org.apache.tools.ant.listener.ProfileLogger
Also gone through groovy method, but is there any other way I can specify Listeners&Loggers in my script.
Thanks
RSA is built on Eclipse. Both let you select an Ant builder for a project. Which gives you all the Ant options including a command line.

how do i run command-line ant with stuff in the classpath?

In eclipse, I can tell my external ant tool to run with stuff in the classpath.
If i want to run ant from the command line, how would i do that?
For argument's sake, the classpath i want to add is c:\some\folder\here\hooray.jar
Use the -lib argument. From the Ant docs on this page:
Additional directories to be searched may be added by using the -lib option. The -lib option specifies a search path. Any jars or classes in the directories of the path will be added to Ant's classloader.

ant target doesn't exist but gets executed

i have never seen this strange -
i am into maintenance project where i got a build.xml and i never installed ant. ant is bundled into the project and so i use -
ant deploy_project.
but when i look at build.xml i cannot find any target named "deploy_project".
can anyone help me how the "deploy_project" target gets executed without this target being present in build.xml?
I suspect that since i didn't install ant by myself and is bundled with the project, any configuration of ant may have been overridden...but how to find it is where i am stuck, can any one pls help me?
(I am sure the target isn't present in build.xml).
thanks much in advance.
Run the following command:
$ ant -p
This will usually print out all the targets in your build.xml. Or at least the ones with descriptions.
Also look for <import file="..."> statements in your build.xml. These allow you to import other Ant build files which can contain targets that aren't in your build.xml. I suspect, if you do a search for the string deploy_project in your build.xml, and you can't find a target by that name, you have an import statement somewhere in your build.xml, so search for <import.
If you are SURE that the target is not present, and you are not specifying the build file with -f option, then only 1 explanation I can think of -
your ANT_HOME is somewhere else and there will be another build.xml there.
(Quickest way to check is find it - SET for Windows echo $PATH for Unix), find the value for ANT_HOME and in the same directory, a build.xml will be present with your *INVISIBLE* target
If you have searched the C: drive and still cannot find any build.xml, then the bundled ANT you have might be a customized one or an ANT wrapper. Meaning have a .bat file called ant.bat which accepts deploy_project as an argument and then maps it to another task using variable substitution. So look for a batch file ant.bat or anything titled ant.

"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.

Is there a way to use just build command instead of ant build while using ant scripts?

I am using Apache Ant scripts for building a web application. I have written some targets in the build.xml file and the script is running fine. I remember using just "build" command to run ant build instead of "ant build". Can anyone tell me how is that achieved? I was a bit curious on this.
There's no built in "build" command. You could create a simple script file called "build" in the same directory that launched the ant build.
Create a text file with this as the contents:
ant build
In windows save this as a file called build.bat then you can just type build from the command line to start your build.
On unix or linux, save the file as build, then make it executable (with chmod +x build). You'll need to type ./build to get it to run.
I don't think there's a lot of value doing this to replace the simple case of ant build, but if you have to regularly run a build that has multiple targets, or need to pass in certain system variables then it could come in useful.
Maybe your are remembering typing "ant" instead of "ant build" in the past. This is possible to setup. You just need to set default attribute on the root project element in your Ant script to the name of the target you want invoked when an explicit target isn't specified.
For instance...
<project name="myproj" default="build">
...
</project>

Resources