adding comment in .properties files

The property file task is for editing properties files. It contains all sorts of nice features that allow you to modify entries. For example: <propertyfile file=”build.properties”> <entry key=”build_number” type=”int” operation=”+” value=”1″/> </propertyfile> I’ve incremented my build_number by one. I have no idea what the value was, but it’s now one greater than what it was … Read more

How in Ant output values of properties?

This statement: <property file=”${user.home}/build.properties”/> Reads a property file(i.e. all properties in that file), and does not set the property named file. This would be correct. You first set a property and then echo it: <property name=”file” value=”${user.home}/build.properties”/> <echo message=”${file}” />

Execute Ant task just if a condition is met

An Ant target can have an optional if or unless clause. This means to execute the task only if the property is set, with an if clause, or is unset with the unless clause1. Interestingly, that if or unless clause is checked after any dependent task is first executed. This means, you can do this … Read more

How to debug Java code when using ANT script in Eclipse

(Wasn’t able to comment on the given answer, so have to make another answer) I realized that when launching Ant from Eclipse, you’ll have to add fork=”true” to the <java> task. Also, it was first not clear to me how to write nested jvmargs, so here goes an example: <java classname=”…” fork=”true”> <jvmarg value=”-Xdebug” /> … Read more

Ant error when trying to build file, can’t find tools.jar?

Java ships in 2 versions: JRE & SDK (used to be called JDK) The JRE in addition to not containing the compiler, also doesn’t contain all of the libraries available in the JDK (tools.jar is one of them) When you download Java at: http://java.sun.com/javase/downloads/index.jsp, make sure to select the JDK version and install it. If … Read more

How to set the path environment variable from ant script

Is this for an <exec> task? You can set environment variables when you run an <exec> task: <exec executable=”${my.command}”> <env key=”foo” value=”bar”/> <arg line=”some value”/> </exec> You can use <property environment=”env”/> to expand the path: <property environment=”env”/> <exec executable=”${my.command}”> <env key=”PATH” value=”${env.PATH}:${my.directory}”/> </exec> If this is for some custom task that requires an environment variable, … Read more

Unable to find a javac compiler

All your ant stuff will work fine except the javac task which needs the tools.jar, located in the /lib directory from the JDK, JRE is not sufficient in that case. Therefore the hint from ant : “Unable to find a javac compiler;…” When working with Eclipse the default setting points to your JRE installation. So, … Read more