nat*_*j07 7 java jar properties
我有一个简单的应用程序,可以读取和写入属性文件.它是在NetBeans中开发的,当从Netbeans内部运行时工作得很好.但是,现在我已经构建并部署了无法找到的属性文件.
项目结构
com/company/projectname/controller/controllerclass.java <- this is where the code using the properties file exists
conf/runController.properties <- the properties file, this exists here
Run Code Online (Sandbox Code Playgroud)
在代码中我有以下访问属性文件:
private final String PROPERTIESFILELOCATION = "conf/runController.properties";
public void runController(){
this.runController = new Properties();
this.propertiesLocation = this.getClass().getClassLoader().getResource(this.PROPERTIESFILELOCATION);
FileInputStream propsInput = new FileInputStream(this.propertiesLocation.getFile());
this.runController.load(propsInput);
}
Run Code Online (Sandbox Code Playgroud)
(为简洁起见)
当我从命令行调用jar文件时,我发出:
java -classpath /usr/java/projectdirectory/project.jar com.company.projectname.controller.controllerclass arg1
Run Code Online (Sandbox Code Playgroud)
所以,我已经成功地在其他项目上实现了这一点,但由于某种原因,这是行不通的.
我已经检查了jar文件中的结构,并且所有内容都符合预期.
任何人都可以指出我的错误,并帮我启动并运行吗?
编辑 - 更改名称以匹配.它们在我的代码中始终保持一致
感谢大家的帮助,特别是 dashrb,为您的代码加 1。
在你的帮助下我设法让它工作。这个问题的最终解决方案是稍微改变策略。
由于我需要读取和写入文件(可能在我的操作中不清楚),我转而使用 Apache.commons.configuration。
也就是说,该线程中的指针确实确保了我的其他属性文件正常工作。
再次感谢