Solved

Updating properties file inside JAR

Posted on 2003-11-27
28
812 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

617 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