【问题标题】:Java : Where exactly the Properties would be configured?Java:属性将在哪里配置?
【发布时间】:2011-12-09 11:34:44
【问题描述】:

在我的 Java 类中说 Props.java File 。 我有这个静态块,如图所示

static
  {
    instanceName = System.getProperty("bayer.instanceName");
    systemPath = System.getProperty("bayer.home");
    if (systemPath == null)
      systemPath = ".";
    propsFile = new File(System.getProperty("bayer.home") + File.separator + "bayer.properties");
  }

请告诉我这些属性bayer.instanceName 和bayer.home 将在哪里定义?? 有关更多信息,我正在使用 Apache Tomcat 6.0 服务器和 Linux 环境。

【问题讨论】:

标签: java tomcat properties


【解决方案1】:

使用-Dpropertyname=value语法在java命令行上设置系统属性,例如:

java -cp someclasspath -Dbayer.instanceName=foo com.mycompany.MyClass

请参阅this answer 了解更多信息。

【讨论】:

  • 我认为java -cp someclasspath -Dbayer.instanceName=foo com.mycompany.MyClass 是正确的。在您的情况下,-Dbayer.instanceName=foo 将被视为第一个系统参数
  • 嗨,从链接中我发现这很有用,环境变量是在操作系统中设置的,例如在 linux export HOME=/Users/myusername 或 windows SET WINDIR=C:\Windows 等中。但是如何查看属性文件??
  • @yyyi777 您的应用程序必须主动加载一个属性文件——它不是自动的。检查代码以找出正在加载的文件
【解决方案2】:

另一个标准位置是

$TOMCAT_HOME/bin/setenv.sh

如果你没有找到它们,请发送grep bayer.home $TOMCAT_HOME/bin

另一个要检查的资源是依赖于您的系统的初始化脚本。见/etc/init.d

【讨论】:

    猜你喜欢
    • 2013-09-23
    • 2015-04-07
    • 2011-08-15
    • 2016-10-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    相关资源
    最近更新 更多