简体   繁体   English

更改Apache Tomcat中的站点级别配置

[英]Change site level configuration in Apache Tomcat

I have build a rest service in Java. 我已经用Java建立了一个REST服务。 For that there is a configuration file that I have to place in /home/user1/ where user1 in the one where tomcat is running. 为此,我必须在/home/user1/中放置一个配置文件,其中user1在运行Tomcat的位置。 If I change the path and move it to the /home/user1/workspace/myRest/ (it is eclipse workspace where I build project) then tomcat gave exception that file not found. 如果我更改路径并将其移动到/home/user1/workspace/myRest/ (这是我在其中构建项目的Eclipse工作区),则tomcat会给出该文件未找到的异常。

How do I inform tomcat that where you should look for the configuration file ? 如何通知tomcat应该在哪里寻找配置文件? This file is being accessed by a jar in my project. 我的项目中的jar正在访问此文件。

you can define a system varible when starting tomcat. 您可以在启动tomcat时定义系统变量。 and access it from your library. 并从您的图书馆访问它。

for example inside your catalina.bat(on windows)/setenv.sh(linux) 例如在您的catalina.bat(在Windows中)/setenv.sh(Linux)内部

windows 视窗

set JAVA_OPTS=%JAVA_OPTS% -Dconfig.path=%CATALINA_HOME%/{path to conf file}

linux linux

JAVA_OPTS="$JAVA_OPTS -Dconfig.path=$CATALINA_HOME/{path to conf file}"

then access it from your code 然后从您的代码访问它

 System.getProperty("config.path")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM