【问题标题】:Root path in the *.properties file*.properties 文件中的根路径
【发布时间】:2011-06-23 07:16:16
【问题描述】:

我有一个 *.properties 文件,其中包含一些配置,我有一个“file=”键,我需要在其中指定文件的路径。现在,我的文件位于我的 Web 应用程序的根文件夹中。如何在 *.proprietes 文件中指定我的 Web 应用程序的根目录?

有点像

file=${root}/file.extension

【问题讨论】:

    标签: java configuration jakarta-ee


    【解决方案1】:

    当您在 Web 应用程序中读取属性文件时,以编程方式将 ${root} 替换为 getServletContext().getRealPath("/");

    【讨论】:

    • 听起来很有趣,如何添加 getServletContext().getRealPath("/");在something.proprietes? :)
    • 你不能像 epoch 说的那样,你必须在你的属性文件中指定你想要的根文件夹,然后在你阅读它时翻译它。
    • @hoss,不,你不能这样做,我的意思是你在物理上读取属性文件的地方,然后用调用的结果替换你的根变量。
    • @Dmitri, @epoch,请举个例子?
    • 嗯,myProps.getProperty("file").replace("${root}", getServletContext().getRealPath("/"));。假设您在某个可以访问 servlet 上下文的地方。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 2013-09-23
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多