0

这个问题已经在 Stackoverflow 中被问过很多次,但是那里提供的解决方案在我的情况下不起作用。

我们在JVM-10win-64位上使用 ant 脚本创建 war 文件,并将文件保存在Tomcat-9的 webapps 文件夹中。我们正在尝试从外部属性文件加载资源包。为此,我们有 2 个属性文件,我们保存在 C:\Program Files\Ticket App\internalproperties 和 C:\Program Files\Ticket App\externalproperties 文件夹中。

我们尝试在 setclasspath.bat 中设置类路径:

set CLASSPATH=C:\Program Files\Ticket App\internalproperties;C:\Program Files\Ticket App\externalproperties;%JAVA_HOME%\lib\tools.jar;

它没有用。我们还尝试将以下代码保留在 setenv.bat 中

set CLASSPATH=%JAVA_HOME%\lib\tools.jar;C:\Program Files\Ticket App\internalproperties;C:\Program Files\Ticket App\externalproperties;%JAVA_HOME%\lib\tools.jar;

两次 Tomcat 都试图从目录C:\apache-tomcat-9.0.12-windows-x64\apache-tomcat-9.0.12\bin 中选择文件。

如果您能在这方面帮助我们,那将非常有帮助。提前致谢。

4

1 回答 1

0

对于 Linux 上的 Tomcat 9.0.14,它适用于我。

在 Tomcat 的 setenv.sh 中,我有这一行 export CLASSPATH=/opt/abc/conf

并且下面的 java 程序可以工作并且 abc.properties 在 /opt/abc/conf 下

    Properties prop = new Properties();
    InputStream input = null;
    try{
    input =prop.getClass().getResourceAsStream("/abc.properties"); 
    prop.load(input);
    System.out.println(prop.getProperty("change.monitor.interval"));
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    } 

Windows 中的行为也应该相同。

于 2019-03-07T14:46:11.080 回答