[英]wildfly: reading properties file from classpath directory
I'm trying to read deployment specific information from a properties file in my claspath folder.我正在尝试从我的 claspath 文件夹中的属性文件中读取部署特定信息。 War file is deployed on wildfly 13 via domain mode.
War 文件通过域模式部署在 wildfly 13 上。
/opt/wildfly/domain/servers/APPS1/tmp/vfs/temp/tempe22b1a59c629344/content-35e1234535af2e86/WEB-INF/classes/bis/com/test/config/application.properties /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我只得到 /opt/wildfly/domain/servers/APPS1/tmp
I am running this code from this class bis.com.test.module.app我正在从此类 bis.com.test.module.app 运行此代码
bis|com|test|module|app.class bis|com|test|module|app.class
bis|com|test|config|application.properties 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?但是我得到所有空指针异常...我如何绕过/访问/检索临时文件夹并进入 WEB-INF 文件夹? 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:经过一番挖掘,我发现您的
application.properties
位于一个包下,因此应该按如下方式访问它:
ClassLoader loader = getClass().getClassLoader();
inputStream = loader.getResourceAsStream("/bis/com/test/config/application.properties");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.