Tuesday 9 July 2019

Maven: Access java system properties in pom.xml file


You can access all the properties that are exposed by 'System.getProperties()' API in pom.xml file.

Below program print all the system properties.
package com.sample.app;

import java.util.Properties;
import java.util.Set;

public class Test {

 public static void main(String args[]) {
  Properties properties = System.getProperties();

  Set<Object> keys = properties.keySet();

  for (Object key : keys) {
   System.out.println(key + " : " + properties.getProperty(key.toString()));
  }
 }
}

Below are some of the examples of the properties that are exposed by 'System.getProperties()' API.

os.name
sun.jnu.encoding
java.library.path
user.home
user.language

You can access above java system properties by using $ notation like below.

${os.name}
${sun.jnu.encoding}
${java.library.path}
${user.home}
${user.language}


Previous                                                    Next                                                    Home

No comments:

Post a Comment