aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to read a property from a properties file in Ant? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to read a property from a properties file in Ant?" Watch "How to read a property from a properties file in Ant?" New topic
Author

How to read a property from a properties file in Ant?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Ant 1.6. I have this target ...

<target name="gen-web-svc-client-jar">
<clientgen
wsdl="${basedir}/wsdl_files/ProvisioningService.wsdl"
destFile="${deployment}/APP-INF/lib/ProvisioningServiceClient.jar"
packageName="com.myco.nps.regui.provisioning.client"
serviceName="ProvisioningService"
classpath="${java.class.path}"
>
<classpath>
<path refid="project.class.path" />
</classpath>
</clientgen>
</target>

For the property, 'wsdl="${basedir}/wsdl_files/ProvisioningService.wsdl"', I would prefer to read this property out of a properties file I have, which has the line ...

PROVISIONING_SERVICE_WSDL_URL=http://99.99.99.99:9999/ProvisioningAccountService/ProvisioningAccountService?WSDL


How can I tell ant to get the value from this file?

Thanks, - Dave
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
You can use loadproperties + filterchain (if you want to read only one property) task

Have a look at http://ant.apache.org/manual/CoreTasks/loadproperties.html
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Check out the 'file' attribute of the Property task.


JBoss In Action
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

Thanks for this info but after reading the link (http://ant.apache.org/manual/CoreTasks/loadproperties.html), I'm still unsure of how to reference the property I want in my Ant script. So I have

<loadproperties>
<file file="file.properties"/>
</loadproperties>


which fill load the properties file, but then how do I reference the "PROVISIONING_SERVICE_WSDL_URL" property within that file? - Dave
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Try this:




When the properties file is read, every property in that file becomes a property in Ant, which can be accessed in the typical Ant fashion of enclosing it within "${}".
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
When I added the line you suggested (with '<properties file="conf/${env}/app.properties" />') I got this error ...


build.xml:39: Could not create task or type of type: properties.

Ant could not find the task or a class this task relies upon.


I'm using Ant 1.6. Sadly, it being a company standard at the moment, I don't have an option to upgrade. Is this a version issue?

Thanks, -
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Sorry, typo. Use "property" not "properties".
 
Consider Paul's rocket mass heater.
 
subject: How to read a property from a properties file in Ant?