[英]wildfly: reading properties file from classpath directory
我正在尝试从我的 claspath 文件夹中的属性文件中读取部署特定信息。 War 文件通过域模式部署在 wildfly 13 上。
/opt/wildfly/domain/servers/APPS1/tmp/vfs/temp/tempe22b1a59c629344/content-35e1234535af2e86/WEB-INF/classes/bis/com/test/config/application.properties
当我尝试使用以下方法获取路径时
System.getProperty(jboss.server.temp.dir)
我只得到 /opt/wildfly/domain/servers/APPS1/tmp
我正在从此类 bis.com.test.module.app 运行此代码
bis|com|test|module|app.class
bis|com|test|config|application.properties
我试过了
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");
但是我得到所有空指针异常...我如何绕过/访问/检索临时文件夹并进入 WEB-INF 文件夹? 由于当前的设计逻辑,我无法将应用程序属性移到别处。 我只能在这里访问属性文件。 如何?
经过一番挖掘,我发现您的application.properties
位于一个包下,因此应该按如下方式访问它:
ClassLoader loader = getClass().getClassLoader();
inputStream = loader.getResourceAsStream("/bis/com/test/config/application.properties");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.