I have a simple application that reads and writes to a properties file. It was developed at NetBeans, and when run from Netbeans it works fine. However, now I created and deployed it, and the properties file was not 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 for accessing 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); }
(summary for brevity)
When I call the jar file from the command line, I output:
java -classpath /usr/java/projectdirectory/project.jar com.company.projectname.controller.controllerclass arg1
So, I managed to achieve this earlier in other projects this way, but for some reason this does not work.
I checked the structure inside the jar file and everything is there as expected.
Can someone point out my mistake and help me deal with this?
EDIT - changed the names to match each other. They were always in my code.
nathj07
source share