Monday 30 October 2017

ANT : How to get User, OS name and Environment properties

Here is what you need to do if you want to fetch below in/using ANT:

a. Logged user - built-in property
b. Machine OS name - built-in property
c. Environment properties - ANT provides a property task which has an attribute environment. Thus if you specify the task with environment="myenv" you will be able to access OS-specific environment variables via property names "myenv.PATH" or "myenv.TERM".


Below is a sample ant script.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="systeminfo">
  <target name="systeminfo">
    <property environment="my_env" />
    <echo>
      User is ${user.name}
      OS Name is ${os.name}     
      ANT_HOME is set to ${my_env.ANT_HOME}
    </echo>
  </target>
</project>
Output:

BuildFile: build.xml systeminfo
[echo]
[echo] User is nadimwarsi
[echo] OS Name is Windows 10 Enterprise
[echo] ANT_HOME is set to C:\Program Files\Java\jdk1.7
[echo] BUILD SUCCESSFUL
Total time: 0 seconds

Helpful? Please Comment.

Happy Learning!!

No comments:

Post a Comment

OSB 12c : Dynamic Routing to Business/Proxy Service

Dynamic routing is a kind of  Content-based Routing pattern, which is used when the BusinessService/ProxyService path is required to be de...