Java 在不重复构建web应用程序的情况下获取属性文件中的更改

Java 在不重复构建web应用程序的情况下获取属性文件中的更改,java,web-applications,war,properties-file,Java,Web Applications,War,Properties File,我创建了一个web应用程序,在一个单独的文件夹中,我已经添加到classpath中,我有一个属性文件。我正在使用 public static Properties getProps() { Properties properties = new Properties(); try { properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("mdmdem

我创建了一个web应用程序,在一个单独的文件夹中,我已经添加到classpath中,我有一个属性文件。我正在使用

public static Properties getProps()  {
    Properties properties = new Properties();
    try {
        properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("mdmdemo.properties"));
    } catch (IOException ex) {
        Logger.getLogger(BasicUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
    return properties;
}
拿到钥匙没问题。然而,尽管我将属性文件放置在war之外,但在构建和部署war之前,我无法看到在prop file中所做的更改。我还反复创建新的属性对象以查看更改,而不仅仅是在web应用程序初始化中

我知道,在这种情况下,使用数据库是更好的解决方案,但我不允许这样做


如何获得更改?

缓存可能是特定于CassLoader的。如果使用tomcat,这将有助于:

ClassLoader ctxLoader=Thread.currentThread().getContextClassLoader();
URL resURL=ctxLoader.getResource(resName);
URLConnection resConn=resul.openConnection();
resConn.setUseCaches(false);

InputStream resIn=resConn.getInputStream()虽然我也怀疑缓存问题,但我使用

properties.load(new FileInputStream("/absolute/path/to/filename.properties");

不使用ClassLoader解决了这个问题

如果仅在部署war时调用
getProps()
,则您永远不会注意到属性文件中的更改。您需要在包含该文件的目录上设置监视服务。检查我在servlet的doGet()函数中调用getProp()。页面本身会定期刷新。我觉得应该够了,我错了吗?听起来应该够了。不,那也不行。虽然我在使用jboss,但我试过了,但没有办法。很高兴认识@cedricc