I am using Ant as our setup script for our server, and we need to get the fully qualified name of our server. How can I get it using Ant, or is is possible in Ant?
The fully qualified hostname is like: xxx.company.com
I am using Ant as our setup script for our server, and we need to get the fully qualified name of our server. How can I get it using Ant, or is is possible in Ant?
The fully qualified hostname is like: xxx.company.com
There is an Ant task called
HostInfo
that you can use to set properties containing the host name and domain of the current machine.Alternatively, if you're running on Linux/Unix you could just call out to the
hostname
command:The fully-qualified host name is then available in
${myhostname}
.EDIT: For a fully platform-independent solution, a custom task something like this (untested) should do the job:
This can be used as follows:
Another approach is to write a javascript scriptdef that sets this information in properties.
You can call it like this:
Here is the result:
This is based on some advice I found here: http://grokbase.com/t/ant/user/051sygfj9b/any-way-to-get-at-the-machine-name
will work on linux and windows, otherwise use the groovy solution from Marc O'Connor
Also nslookup will work on linux and windows, if you need the fullhostname you have to parse for the entry after Name: in
nslookup ServerName
output, use :use enviroment
Use javascript which is built-in
Rehashing an answer I did for Maven :-)
Use an embedded groovy script to perform the Java hostname lookup:
Example
Project is self-documenting:
build.xml