Link to home
Start Free TrialLog in
Avatar of shji1
shji1

asked on

Updating properties file inside JAR

Hi,
I am trying to write a small app. that needs to save some input data and use it the next time it is being executed.
Currently, the application is executed by using an executable JAR and I don't wish to change it. The thing is that I also don't wish to write any external resource files near that jar.
My question is how can I write, or actually update, a properties file within the jar file without destroying the JAR content(and doing it at runtime).
Code snippet will be the best...
Thanks!
--me
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland 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
ASKER CERTIFIED SOLUTION
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
Avatar of shji1
shji1

ASKER

Can I load the content to to the memory and then write it back to the same JAR with the modifications?
Wont it throw exceptions for the application already running?
--
>>Can I load the content to to the memory and then write it back to the same JAR with the modifications?

No
Avatar of shji1

ASKER

depressing...
> Can I load the content to to the memory and then write it back to the same JAR with the
> modifications?

that was the first alternative I suggested trying.
Easiest would be to store the properties file in it's own jar.

What exactly is you want to achieve, and why don't you want to store it externally?
Avatar of shji1

ASKER

I guess CEHJ already tried it before...

> Easiest would be to store the properties file in it's own jar.
Easier to just save it outside as is.
Avatar of shji1

ASKER

I don't want it to be so easily modified by any curious person.
>>I guess CEHJ already tried it before.

No - i haven't - that's why i expressed doubt originally. I'm quite willing to be convinced otherwise though by some concrete evidence ;-)
> I don't want it to be so easily modified by any curious person.

No difference if its in it own jar, or if its in the same jar as app.
Other option is to simply encode it somehow.
Avatar of shji1

ASKER

I guess it's a matter of preference.
:)
Storing it externally, actually makes it a little harder cause the user doesn't know where the properties file is.
Avatar of shji1

ASKER

This is true if you are the one installing it. It's not the case here.
It's a very small app that I wish to mail to some people.

Well... At least you saved me time (-;
 Remind me how can I split the points?
Avatar of shji1

ASKER

o... found it (-:
Clarification here - where are we? Write to own jar possible or not?
Avatar of shji1

ASKER

probably write it to external properties file.
had to compromise....
Ah - i was hoping you were going to keep this open until you'd established whether this is possible...
Avatar of shji1

ASKER

O... Sorry (-:
Actually I still think it's possible to load all the jar data into byte[] buffers and then to write it back to the same jar on runtime.
I just hoped that I wont have to do it and then realise that it can't be done. But now, I think I am going to try anyway.
I'll try to let you know somehow.
--
OK - keen to know. Please post in here later.
The only possible problem with writing back to the same jar would be that it is already open.
I'm 99% certain it's not possible
On MSWindows you can!
Download TotalCommander from http://www.ghisler.com/
then associate the properties file with an editor (e.g. notepath)
in TotalCommander, open the .jar as if it were a .zip file (Ctrl/PgDn),
click on the file to edit and your editor pops up with the file.
Afterwards save and close.
TotalCommander asks you if the .jar must be refreshed; say Yes.

The utility mentioned is Freeware, so you don't have to buy it yet.
;JOOP!
I'm more than a little mystified by that last comment ;-) shji1 is talking about a programmatic write to a running program's own jar...
You are right; sorry.
;JOOP!
8-)
Do you know an icon for a blush ......?








(joop)
There may be one in the Unicode set..;-)