There is an Ant task called HostInfo , which you can use to set properties containing the host name and domain of the current computer.
Alternatively, if you are running Linux / Unix, you can simply invoke the hostname command:
<exec executable="hostname" outputproperty="myhostname"> <arg line="-f"/> </exec>
A full hostname is available in ${myhostname} .
EDIT: For a solution completely independent of the platform, a user task like this (unchecked) should complete the task:
public class GetHost extends Task { private String property; public void setProperty(String property) { this.property = property; } @Override public void execute() throws BuildException { if (property == null || property.length() == 0) { throw new BuildException("Property name must be specified."); } else { try { String hostName = InetAddress.getLocalHost().getHostName(); getProject().setProperty(property, hostName); } catch (IOException ex) { throw new BuildException(ex); } } } }
This can be used as follows:
<GetHost property="myhostname" />
source share