This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access ANT properties in Java program

 
Raj Maheshwari
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I want to access ant properties which are declared in various targets in the program from my java program. Is this possible? If so can someone please tell me how?

Thanks
Raj
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few more details about what you're trying to do and what hasn't worked might be helpful.

But I'll assume you are using the java task. Are you trying to pass in command-line arguments or access the ant properties like system properties or ?

The ant manual on Java Task indicates you can use nested arg, jvmarg, sysproperty, and syspropertyset elements with the java task.

If you have a bunch of properties defined elsewhere in your build file and you want to access them like system properties it sounds like the syspropertyset might handle that (syspropertyset is a PropertySet Type)
[ March 15, 2005: Message edited by: Carol Enderlin ]
 
Raj Maheshwari
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carol!

Thanks a lot. Thats exactly what I'm trying to do:
I set a few properties in my build file. I want my java program at runtime to pick up those properties (just like it can pick up system properties). I'll give this a shot today.

Raj
 
Raj Maheshwari
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carol!

Your suggestion did solve a part of my problem - calling it from the Java Task when. However, I still have a problem if my program runs from within a web application. How can it pick up properties at that point?

Thanks
Raj
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the "simple" answer to your question is to pass them in on the command-line.

java -Dprop.name=value ...

There are other ways to deal with properties, though. Such as properties files. e.g. lots of hit on google, Loading properties article

Perhaps this isn't really an ant question at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic