Java 部署时添加属性文件

Java 部署时添加属性文件,java,tomcat,intellij-idea,Java,Tomcat,Intellij Idea,我正在使用IntelliJ 13 Ultimate和tomcat8服务器构建一个web应用程序。 我的TextUtil类旁边有一个属性文件,以便使用 TextUtil.class.getResource(TEXT_PROPERTY_PATH).getFile() 但是,当我用IntelliJ启动服务器时,默认情况下不会复制文件(这很符合逻辑,因为它不是编译器输出的一部分) 我编辑了工件并手动添加了文件。但通过这样做,在不重新启动服务器的情况下,文件不会随更改而更新 有吗 A) 属性文件的更好

我正在使用IntelliJ 13 Ultimate和tomcat8服务器构建一个web应用程序。 我的TextUtil类旁边有一个属性文件,以便使用

TextUtil.class.getResource(TEXT_PROPERTY_PATH).getFile() 
但是,当我用IntelliJ启动服务器时,默认情况下不会复制文件(这很符合逻辑,因为它不是编译器输出的一部分)

我编辑了工件并手动添加了文件。但通过这样做,在不重新启动服务器的情况下,文件不会随更改而更新

有吗

A) 属性文件的更好位置,在这里我可以在没有上下文对象或


B) 将文件保留在原处并在更改时更新的方法?

您可以将文件添加到类路径中,并使用下面的代码生成inputstream

例如,在ABC.properties或类似properties/ABC.properties的文件夹中

public class TextUtil {

....................

//For ABC.properties
 InputStream inStream1 = TextUtil.getClass()
          .getClassLoader().getResourceAsStream("ABC.properties");

//For properties/ABC.properties
InputStream inStream2 = TextUtil.getClass()
          .getClassLoader().getResourceAsStream("properties/ABC.properties");

 ....................
 }
注意: 正确构建后,它应该转到路径/WEB-INF/classes//ABC.properties

public class TextUtil {

....................

//For ABC.properties
 InputStream inStream1 = TextUtil.getClass()
          .getClassLoader().getResourceAsStream("ABC.properties");

//For properties/ABC.properties
InputStream inStream2 = TextUtil.getClass()
          .getClassLoader().getResourceAsStream("properties/ABC.properties");

 ....................
 }