Solved

compiling java each time properties file is changed

Posted on 2007-03-23
11
191 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:ams7503
11 Comments
 
LVL 20

Expert Comment

by:gatorvip
ID: 18781284
>>However each time I change the location of the input file

Explain, please
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18781360
Make sure you've closed the Properties input stream before you try to read it again
0
 

Author Comment

by:ams7503
ID: 18781383
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.
0
 

Author Comment

by:ams7503
ID: 18781563
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?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18781623
>>
Properties props = new Properties();
File data = new File(props.getProperty("inputFile"));
>>

Not possible. 'props' is empty
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:ams7503
ID: 18781655
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18782341
That's fine. Can you show me the *re*reading code?
0
 

Author Comment

by:ams7503
ID: 18782375
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18782387
OK - glad it's working
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 19501793
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now