Load properties file in a java servlet deployed in JBoss as a war

后端 未结 4 741
你的背包
你的背包 2021-01-02 12:03

I have a servlet deployed as a war in JBoss 4.0.2. I have a properties file for the deployed application. Where should I put this file? Under the conf directory in the jbo

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-02 12:27

    Just get hold of the servletContext and then

    InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/log4j.properties");
    Properties props = new Properties();
    props.load(stream);
    

    This will always work, regardless of whether you deploy a war or exploded war.

提交回复
热议问题