wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Access ANT properties in Java program 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 "Access ANT properties in Java program" Watch "Access ANT properties in Java program" New topic
Author

Access ANT properties in Java program

Raj Maheshwari
Ranch Hand

Joined: Jul 02, 2004
Posts: 34
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

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Jul 02, 2004
Posts: 34
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

Joined: Jul 02, 2004
Posts: 34
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

Joined: Oct 10, 2000
Posts: 1364
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access ANT properties in Java program
 
Similar Threads
Ant error on trying to run an taskdef
accessing windows regedit
Eclipse 2.0 Ant not as verbose as Ant on command line?
Ant and system date / time
How to access properties file from WEB-INF/ directory