【问题标题】:Setting the path of properties file along with Java command使用 Java 命令设置属性文件的路径
【发布时间】:2013-10-07 05:57:19
【问题描述】:

我创建了一个 shell 脚本来在 Ubuntu 中运行我的项目。在那里,我必须提供属性文件路径以及 Java 命令。

我正在使用此命令执行此操作,但它不工作文件未加载,并且在我尝试使用它时它正在提供NullPointerException

/usr/lib/jvm/java-7-openjdk-i386/bin/java" -cp $CLASSPATH -Doligosoft.POSconfig.file=/home/mlpc04/Paritosh/POS_3.0/resources/posconfig.properties com.floreantpos.main.Main

在 Classpath 中,我已经正确给出了该文件所在的位置,但不知道出了什么问题,请建议我使用的命令是正确的,或者问题出在其他问题上。

编辑

private static void loadPosConfig() {
     String filename = System.getProperty( "oligosoft.POSConfig.file" ); 
     posConfig = new Properties(); System.out.println(filename); 
     File file = new File(filename); 
     System.out.println( file.getAbsolutePath()); 
     FileInputStream inputStream = null; 
     try { 
        inputStream = new FileInputStream( file ); posConfig.load(inputStream);
     } catch ( Exception e) { logger.error( "Not able to load configuration" , e ); }

我在我的应用程序的这种方法中使用该文件,但我试图通过我的脚本提供这个文件。

【问题讨论】:

  • 您应该在加载属性文件的位置发布代码。否则你的问题太模糊了
  • 私有静态 void loadPosConfig() { 字符串文件名 = System.getProperty( "oligosoft.POSConfig.file" ); posConfig = 新属性(); System.out.println(文件名);文件文件 = 新文件(文件名); System.out.println(file.getAbsolutePath()); FileInputStream inputStream = null;尝试 { inputStream = new FileInputStream( 文件 ); posConfig.load(inputStream); } catch ( Exception e) { logger.error( "无法加载配置" , e );我在我的应用程序的这个方法中使用该文件,但我试图通过我的脚本提供这个文件。

标签: java shell


【解决方案1】:

您在使用 -Doligosoft.POSconfig.file=... 而不是 -Doligosoft.POSConfig.file=... 的 shell 调用中有错字

【讨论】:

  • 我看不懂,请详细说明。
  • 您需要在 POSConfig 中使用大写 C 而不是 POSconfig
猜你喜欢
  • 2018-07-26
  • 1970-01-01
  • 1970-01-01
  • 2015-09-21
  • 2011-10-05
  • 1970-01-01
  • 2011-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多