Ever waste time searching for a certain property you need to build an Ant target? Here’s a quick tip to save you some time – echoproperties
. According to The Apache Ant Project website, the echoproperties
task ” displays all the current properties (or a subset of them specified by a nested <propertyset>
) in the project. The output can be sent to a file if desired. This task can be used as a somewhat contrived means of returning data from an <ant>
invocation, but is really for debugging build files.”
Recently, I was working on a new Java Web Application Project in NetBeans IDE 7.2.1. I wanted to build an Ant target to automate the deployment of the project’s .war file to GlassFish. To do so, I needed to identify properties that could return 1) the project’s name, 2) the path to the project’s .war file, and 3) the path to GlassFish’s asadmin
utility. Calling the echoproperties
task from within the Ant target below, from within my open project, returned a list of over 90 property key/value pairs.
<target name="list-all-properties"> <echoproperties /> </target>
Although the results were enlightening, I couldn’t find the properties I was hoping to reference in the new target. Next however, I ran the Ant target again, adding the two dependency targets my GlassFish deployment target was going to need, clean
and dist
.
<target name="list-all-properties" depends="clean, dist"> <echoproperties /> </target>
Running the revised target returned almost 450 properties, all available to Ant. The new properties were a result of the clean
and dist
targets running before the call to echoproperties
. Those target’s properties were now also available. Here is a snippet of the results:
... ant.project.invoked-targets=list-all-properties ant.project.name=MySqlEntityWebDemo ant.version=Apache Ant(TM) version 1.8.3 compiled on February 26 2012 ap.cmd.line.internal= ap.proc.none.internal= ap.processors.internal= ap.supported.internal=true application.args.param= awt.toolkit=sun.awt.X11.XToolkit basedir=/home/gstaffor/NetBeansProjects/MySqlEntityWebDemo build.classes.dir=build/web/WEB-INF/classes build.classes.excludes=**/*.java,**/*.form build.compiler.emacs=true build.dir=build build.dir.to.clean=build/web build.generated.dir=build/generated build.generated.sources.dir=build/generated-sources build.meta.inf.dir=build/web/META-INF build.test.classes.dir=build/test/classes build.test.results.dir=build/test/results build.web.dir=build/web build.web.excludes=**/*.java,**/*.form client.urlPart= compile.jsps=false conf.dir=src/conf debug-args-line=-Xdebug debug-transport=dt_socket debug-transport-by-os=dt_socket debug.classpath=build/web/WEB-INF/classes\:/home/gstaffor/JavaFiles/eclipselink_2_4_1/jlib/eclipselink.jar... debug.test.classpath=/home/gstaffor/JavaFiles/eclipselink_2_4_1/jlib/eclipselink.jar... default.javac.source=1.7 default.javac.target=1.7 deploy.ant.properties.file=/home/gstaffor/.netbeans/7.2/gfv3-430621021.properties display.browser=true dist.dir=dist dist.ear.war=dist/MySqlEntityWebDemo.war dist.jar.dir=/home/gstaffor/NetBeansProjects/MySqlEntityWebDemo/dist dist.javadoc.dir=dist/javadoc dist.war=dist/MySqlEntityWebDemo.war ... j2ee.compile.on.save=true j2ee.copy.static.files.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.6-web j2ee.platform.classpath=/home/gstaffor/glassfish-3.1.2.2/glassfish/modules/bean-validator.jar... j2ee.platform.embeddableejb.classpath=/home/gstaffor/glassfish-3.1.2.2/glassfish/lib/embedded/glassfish-embedded-static-shell.jar j2ee.platform.is.jsr109=true j2ee.platform.wscompile.classpath=/home/gstaffor/glassfish-3.1.2.2/glassfish/modules/webservices-osgi.jar... j2ee.platform.wsit.classpath= j2ee.server.domain=/home/gstaffor/glassfish-3.1.2.2/glassfish/domains/domain1 j2ee.server.home=/home/gstaffor/glassfish-3.1.2.2/glassfish j2ee.server.instance=[/home/gstaffor/glassfish-3.1.2.2/glassfish... j2ee.server.middleware=/home/gstaffor/glassfish-3.1.2.2 j2ee.server.type=gfv3ee6 jar.compress=false ... war.content.additional= war.ear.name=MySqlEntityWebDemo.war war.name=MySqlEntityWebDemo.war web.docbase.dir=web webinf.dir=web/WEB-INF
Reviewing the results, I was able to find all the properties I needed to build the target, below.
<target name="glassfish-deploy" depends="clean, dist" description="Build distribution (WAR) and deploy to GlassFish"> <exec failonerror="true" vmlauncher="false" executable="${j2ee.server.home}/bin/asadmin" > <arg line="--host=localhost --port=4848 --user=admin --passwordfile=pwdfile --secure=false deploy --force=true --name='${ant.project.name}' --contextroot='/${ant.project.name}' '${dist.war}'" /> </exec> </target>
Almost any properties you need to develop an Ant Target is probably available if you know where, or how to look.