I'm trying to read deployment specific information from a properties file in my claspath folder. War file is deployed on wildfly 13 via domain mode.
/opt/wildfly/domain/servers/APPS1/tmp/vfs/temp/tempe22b1a59c629344/content-35e1234535af2e86/WEB-INF/classes/bis/com/test/config/application.properties
When i try to get my path using the following
System.getProperty(jboss.server.temp.dir)
I only get /opt/wildfly/domain/servers/APPS1/tmp
I am running this code from this class bis.com.test.module.app
bis|com|test|module|app.class
bis|com|test|config|application.properties
I have tried
private static final String PATH = "/WEB-INF/classes/bis/com/test/config/application.properties";
Properties props = new Properties();
InputStream in = getClass().getResourceAsStream("/application.properties");
props.load(in);
String JDBC = props.getProperty("jdbc.connection");
Properties props = new Properties();
InputStream in = App.class().getResourceAsStream("/application.properties");
props.load(in);
String JDBC = props.getProperty("jdbc.connection");
Properties props = new Properties();
InputStream in = getClass().getResourceAsStream(PATH);
props.load(in);
String JDBC = props.getProperty("jdbc.connection");
URL url = FacesContext.getCurrentInstance().getExternalContext().getResource(PATH);
Properties app = new Properties();
app.load(url.openStream());
String JDBC = app.getProperty("jdbc.connection");
However im getting null pointer exception for all...how do i bypass/access/retrieve the temp folders and go into the WEB-INF folders? Im unable to move the application properties elsewhere due to current design logic. I only can access the properties file here. how?
After some digging, I found that your application.properties
reside under a package so it should be accessed as given below:
ClassLoader loader = getClass().getClassLoader();
inputStream = loader.getResourceAsStream("/bis/com/test/config/application.properties");