【发布时间】: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 );我在我的应用程序的这个方法中使用该文件,但我试图通过我的脚本提供这个文件。