External Log files from Ant - ant

I have configured Log4j in my project and that is invoked by an Ant task.
I want the Ant logs as well as project logs to be written to single file along with timestamps.
Could you let me know how to take care of this in Ant?

You can run Ant in such a way that it's logging is via Log4j, there's an example in the Ant Listeners & Loggers page:
ant -listener org.apache.tools.ant.listener.Log4jListener
but see the Ant documentation for proper details, how to ensure log4j.properties etc. are found.

Related

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.

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 Script Build Messages into a log4j configured log file

I am developing a java project using Eclipse as IDE and ant as the build tool. For logging I am making use of log4j library. I am able to get the log messages in a log file for my whole application using log4j configuration.
But when I build project using ANT, the ANT build messages are still posted to console.I want to make sure that when I build the project, the build messages that ANT generates, like build failure/success, should also be posted to that sames logger file using log4j.
Please help me in this if anyone has got an idea. Thanks
To pass the logging log4j, you can use this when you run Ant:
$ ant -listener org.apache.tools.ant.listener.Log4jListener
The configuration of log4j is then up to you. See the information on Listeners in the Ant manual.

How to get all dependency jars from build.xml

I have several very big ant build.xml files.
Someone know tool or program for get all dependency jar files from build.xml ?
Please check How To Check Dependencies Between Jar Files?.
http://www.jboss.org/tattletale or jdepend could help in getting dependencies between jars.
If you want to extract dependencies from a given build.xml , one option is to write XML parser and process ant file. Not an easy task. Another option will be write a listener for each build task. If the task is javac then query its classpath.

FindBugs Ant task - how to load preferences file?

I run FindBugs from Ant task. I have preferences file .fbprefs which I want FindBugs to use, so that the bug report produced by Ant matches the one produced by Eclipse.
Unfortunately the ant task is based on filter files, see http://findbugs.sourceforge.net/manual/filter.html
You should start using filter files not the Eclipse plugin configuration. Check this resource: http://docs.codehaus.org/display/SONAR/Project+settings#Projectsettings-Excluderesources
It should help you create a filter which corresponds to your Eclipse FindBugs plugin configuration.

Resources