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
LVL 1
shji1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
AFAIK, that's not possible, but take some other opinions too.
0
objectsCommented:
you can't, options are:
- recreate jar, including properties changes
- use properties file external to jar in a known location such as users home directory
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shji1Author Commented:
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?
--
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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

No
0
shji1Author Commented:
depressing...
0
objectsCommented:
> 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.

0
objectsCommented:
What exactly is you want to achieve, and why don't you want to store it externally?
0
shji1Author Commented:
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.
0
shji1Author Commented:
I don't want it to be so easily modified by any curious person.
0
CEHJCommented:
>>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 ;-)
0
objectsCommented:
> 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.
0
shji1Author Commented:
I guess it's a matter of preference.
:)
0
objectsCommented:
Storing it externally, actually makes it a little harder cause the user doesn't know where the properties file is.
0
shji1Author Commented:
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?
0
shji1Author Commented:
o... found it (-:
0
CEHJCommented:
Clarification here - where are we? Write to own jar possible or not?
0
shji1Author Commented:
probably write it to external properties file.
had to compromise....
0
CEHJCommented:
Ah - i was hoping you were going to keep this open until you'd established whether this is possible...
0
shji1Author Commented:
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.
--
0
CEHJCommented:
OK - keen to know. Please post in here later.
0
objectsCommented:
The only possible problem with writing back to the same jar would be that it is already open.
0
CEHJCommented:
I'm 99% certain it's not possible
0
sciuriwareCommented:
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!
0
CEHJCommented:
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...
0
sciuriwareCommented:
You are right; sorry.
;JOOP!
0
CEHJCommented:
8-)
0
sciuriwareCommented:
Do you know an icon for a blush ......?








(joop)
0
CEHJCommented:
There may be one in the Unicode set..;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.