I have a simple application that reads from and writes to a properties file. It was developed in NetBeans and when run from within Netbeans works just fine. However, now I have built and deployed it the properties file cannot be found.
Project Structure
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
In the code I have the following to access the properties file:
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);
}
(summarized for brevity)
When I call the jar file from the command line I issue:
java -classpath /usr/java/projectdirectory/project.jar com.company.projectname.controller.controllerclass arg1
So, I have managed to achieve this before on other projects in just this way but for some reason this is not working.
I have checked the structure inside the jar file and all is as expected in there.
Can anyone point out my mistake and help me get this up and running please?
EDIT- changed the names to match across. They were always consistent in my code
Thanks to everyone for helping out, especially dashrb, plus 1 for your code.
I managed to get it working with your help. The final solution to this problem was a slight change of tack.
As I had the need to read and write to the file (probably not clear in my OP) I switched to using Apache.commons.configuration.
That said the pointers in this thread did ensure my other properties files were working without hitch.
Thanks again