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
Your question talks about
conf/controller.properties
and your code talks about conf/runController.properties
EDIT: I'm assuming that the conf/*.properties is inside your jar file. If thats the case, then your code should work if the files are named correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With