Link to home
Start Free TrialLog in
Avatar of ams7503
ams7503

asked on

compiling java each time properties file is changed

I have written a java app,which reads a properties file.One of the properties is the location of an input file.
I have compile my code and written a script to run the app.
However each time I change the location of the input file, I need to compile and then run,so that the current file is used.This does not seem to be right.-I thought as long
as you don't make changes to the code there would be no need to compile it over and over again.
Avatar of gatorvip
gatorvip
Flag of United States of America image

>>However each time I change the location of the input file

Explain, please
Avatar of CEHJ
Make sure you've closed the Properties input stream before you try to read it again
Avatar of ams7503
ams7503

ASKER

I cd to the directory where the properties file exists.The properties file has a property called inputfile.
I edit thisfile, by changing the value to some other filename
For eg inputFile=file1.dat- I compile my java code then run the app- the data from file1.dat is used by the java app.
Now,say I changed the filename to file2.dat and did not compile the code and ran the app- the data from file1.dat is still used.I have to compile and then run in order for file2 to be used.
Nothing has changed within any of the java files only an external properties file is being changed and does not need to be compiled.
Avatar of ams7503

ASKER

Thanks for the feedback-
I am not using an input stream to read the properties file, this is how I do it:
Properties props = new Properties();
File data = new File(props.getProperty("inputFile"));
File abbreviations = new File(props.getProperty("abbFile"));
File sic=new File(props.getProperty("sic"))
The only thing that changes in the properties file is the property "inputFile"- I am not sure why consecutive runs is still remembering the old property,unless I compile and then run?
>>
Properties props = new Properties();
File data = new File(props.getProperty("inputFile"));
>>

Not possible. 'props' is empty
Avatar of ams7503

ASKER

sorry- I was wrong.
       java.net.URL url = ClassLoader.getSystemResource("app.properties");
            InputStream is = url.openStream();
            props.load(is);
            is.close();
Then I read the properties-I have already closed the i=InputStream
That's fine. Can you show me the *re*reading code?
Avatar of ams7503

ASKER

Thanks for the response- I thinkI have figured out what is happening. As a part of the build process I was copying the properties to another location, hence each time  I was editing the properties file, the old file was being used.
Thanks
OK - glad it's working
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial