Solved

Updating properties file inside JAR

Posted on 2003-11-27
28
806 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:shji1
  • 10
  • 9
  • 6
  • +1
28 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 9833973
AFAIK, that's not possible, but take some other opinions too.
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 9833983
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
 
LVL 1

Author Comment

by:shji1
ID: 9834041
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9834046
>>Can I load the content to to the memory and then write it back to the same JAR with the modifications?

No
0
 
LVL 1

Author Comment

by:shji1
ID: 9834052
depressing...
0
 
LVL 92

Expert Comment

by:objects
ID: 9834053
> 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
 
LVL 92

Expert Comment

by:objects
ID: 9834057
What exactly is you want to achieve, and why don't you want to store it externally?
0
 
LVL 1

Author Comment

by:shji1
ID: 9834063
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
 
LVL 1

Author Comment

by:shji1
ID: 9834077
I don't want it to be so easily modified by any curious person.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9834084
>>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
 
LVL 92

Expert Comment

by:objects
ID: 9834099
> 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
 
LVL 1

Author Comment

by:shji1
ID: 9834115
I guess it's a matter of preference.
:)
0
 
LVL 92

Expert Comment

by:objects
ID: 9834122
Storing it externally, actually makes it a little harder cause the user doesn't know where the properties file is.
0
 
LVL 1

Author Comment

by:shji1
ID: 9834136
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
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.

 
LVL 1

Author Comment

by:shji1
ID: 9834159
o... found it (-:
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9834162
Clarification here - where are we? Write to own jar possible or not?
0
 
LVL 1

Author Comment

by:shji1
ID: 9834165
probably write it to external properties file.
had to compromise....
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9834168
Ah - i was hoping you were going to keep this open until you'd established whether this is possible...
0
 
LVL 1

Author Comment

by:shji1
ID: 9834180
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9834192
OK - keen to know. Please post in here later.
0
 
LVL 92

Expert Comment

by:objects
ID: 9834220
The only possible problem with writing back to the same jar would be that it is already open.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9834236
I'm 99% certain it's not possible
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 9836662
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9836912
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 9836978
You are right; sorry.
;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9836990
8-)
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 9837019
Do you know an icon for a blush ......?








(joop)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9837037
There may be one in the Unicode set..;-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

705 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

18 Experts available now in Live!

Get 1:1 Help Now