简体   繁体   English

Windows上的Java和环境变量

[英]Java and environment variables on Windows

I use: 我用:

<context:property-placeholder location="file:${PROJECT_CONFIG_PATH}/project.conf" />

in my applicationContext.xml to get local config (one for development and another for production). 在我的applicationContext.xml中获取本地配置(一个用于开发,另一个用于生产)。 PROJECT_CONFIG_PATH is a system environment variable (not eclipse env). PROJECT_CONFIG_PATH是系统环境变量(不是eclipse env)。

It works: on Windows in Eclipse (Jetty) and on Unix. 它的工作原理是:在Eclipse(Jetty)中的Windows和Unix上。

It doesn't work: on Windows with Tomcat 6 ( java.io.FileNotFoundException: ${PROJECT_CONFIG_PATH}\\project.conf ) 它不起作用:在具有Tomcat 6的Windows上( java.io.FileNotFoundException: ${PROJECT_CONFIG_PATH}\\project.conf

Could someone please tell me why Tomcat on Windows doesn't see environment variables? 有人可以告诉我为什么Windows上的Tomcat看不到环境变量吗? And how could this be solved? 以及如何解决?

Thanks in advance! 提前致谢!

If Tomcat is being run as a service, you will need to use the tomcat configuration editor to set the variable. 如果Tomcat作为服务运行,则需要使用tomcat配置编辑器来设置变量。

Start->Programs->Apache Tomcat xx->Configure Tomcat 开始->程序-> Apache Tomcat xx->配置Tomcat

Select the Java tab Add the variable under "Java Options" as: 选择Java选项卡,在“ Java选项”下将变量添加为:

-DPROJECT_CONFIG_PATH="c:/yourpath"

Click OK and then restart the tomcat service. 单击确定,然后重新启动tomcat服务。

尝试这个 ...

<context:property-placeholder location="classpath:/PROJECT_CONFIG_PATH/project.conf" />

I don't think Tomcat's startup batch files inherit the parent environment. 我认为Tomcat的启动批处理文件不会继承父环境。 Not sure why, though. 不过不知道为什么。

Try setting PROJECT_CONFIG_PATH in either catalina.bat or startup.bat in the Tomcat bin directory. 尝试在Tomcat bin目录的catalina.bat或startup.bat中设置PROJECT_CONFIG_PATH

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

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