Tuesday, November 13, 2018

How to use property file in GlassFish

One way:
URL url = this.getClass().getResource("/api.properties");
Properties p = new Properties();
p.load(new FileInputStream(new File(url.getFile())));

The other way:
InputStream in =
this.getClass().getClassLoader().getResourceAsStream("/api.properties");
Properties properties = new Properties();
properties.load(in);
Property file api.properties is put under the resource folder in
NetBean web application project.