Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How can I write values in a properties-File which is located in a JAR without copying the whole JAR?

Reply
Thread Tools

How can I write values in a properties-File which is located in a JAR without copying the whole JAR?

 
 
stanislav.tomic@gmail.com
Guest
Posts: n/a
 
      08-17-2007
Hi people out there

that's my first time in a diskussion-group. Let's see if it works.

I have a question concerning properties-files in Java.

Writing in a properties-file and reading out of the file is working as
long as I don't put my files in a JAR.

The adventureous part of the programm is that I'm trying to make an
application which should be able to remember user-settings (write
values in properties-file) and load them (read out values of
properties-file) when started next time.

I've tried different things, but I don't understand how to combine
UPDATEABLE properties-files with JAR-archives? (How to put a
properties-file in a JAR and write new values into it during
runtime.) Reading is possible with different streams, but where is
the sense of a properties-file if I can't add new data to it, while
the application is running. Is there another way of saving properties
which are necessary for the application? Of course the solution should
only use relativ paths, to make sure that the user is able to access
it.

I would prefer to have my files in a JAR, cause it's easier to
distribute. (The user just has to unzip a ZIP-archive, which includes
a folder with the necessary libraries and a JAR-file with my classes.)

So, that's the problem which I'm trying to solve in the last couple of
days. Is anybody out ther, who can explain me how to solve that
problem?

Thanks in advance for your help,
Stani.

 
Reply With Quote
 
 
 
 
Aaron Steed
Guest
Posts: n/a
 
      08-17-2007
On Aug 17, 3:42 am, (E-Mail Removed) wrote:
> Hi people out there
>
> that's my first time in a diskussion-group. Let's see if it works.
>
> I have a question concerning properties-files in Java.
>
> Writing in a properties-file and reading out of the file is working as
> long as I don't put my files in a JAR.
>
> The adventureous part of the programm is that I'm trying to make an
> application which should be able to remember user-settings (write
> values in properties-file) and load them (read out values of
> properties-file) when started next time.
>
> I've tried different things, but I don't understand how to combine
> UPDATEABLE properties-files with JAR-archives? (How to put a
> properties-file in a JAR and write new values into it during
> runtime.) Reading is possible with different streams, but where is
> the sense of a properties-file if I can't add new data to it, while
> the application is running. Is there another way of saving properties
> which are necessary for the application? Of course the solution should
> only use relativ paths, to make sure that the user is able to access
> it.
>
> I would prefer to have my files in a JAR, cause it's easier to
> distribute. (The user just has to unzip a ZIP-archive, which includes
> a folder with the necessary libraries and a JAR-file with my classes.)
>
> So, that's the problem which I'm trying to solve in the last couple of
> days. Is anybody out ther, who can explain me how to solve that
> problem?
>
> Thanks in advance for your help,
> Stani.


you can open it and edit it with the Winrar program i believe.
Located at http://www.rarlabs.com/
You should be able to open the jar file and edit its contents.

 
Reply With Quote
 
 
 
 
stanislav.tomic@gmail.com
Guest
Posts: n/a
 
      08-17-2007
Thank you for the quick reply Aaron.

I've been thinking about using another application for updating my
existing file too. But I would prefer to do it all in Java without an
external application, because I want to be able to be independent of
other programms.

And then there is also the problem, that during runtime the JAR-
archive won't be accessible.

How do other people solve the problem with the properties-file? Should
I save it in another folder and like my libraries and just access it
with an relative path? Is that possible?

 
Reply With Quote
 
Aaron Steed
Guest
Posts: n/a
 
      08-17-2007
On Aug 17, 3:50 am, Aaron Steed <(E-Mail Removed)> wrote:
> On Aug 17, 3:42 am, (E-Mail Removed) wrote:
>
>
>
> > Hi people out there

>
> > that's my first time in a diskussion-group. Let's see if it works.

>
> > I have a question concerning properties-files in Java.

>
> > Writing in a properties-file and reading out of the file is working as
> > long as I don't put my files in a JAR.

>
> > The adventureous part of the programm is that I'm trying to make an
> > application which should be able to remember user-settings (write
> > values in properties-file) and load them (read out values of
> > properties-file) when started next time.

>
> > I've tried different things, but I don't understand how to combine
> > UPDATEABLE properties-files with JAR-archives? (How to put a
> > properties-file in a JAR and write new values into it during
> > runtime.) Reading is possible with different streams, but where is
> > the sense of a properties-file if I can't add new data to it, while
> > the application is running. Is there another way of saving properties
> > which are necessary for the application? Of course the solution should
> > only use relativ paths, to make sure that the user is able to access
> > it.

>
> > I would prefer to have my files in a JAR, cause it's easier to
> > distribute. (The user just has to unzip a ZIP-archive, which includes
> > a folder with the necessary libraries and a JAR-file with my classes.)

>
> > So, that's the problem which I'm trying to solve in the last couple of
> > days. Is anybody out ther, who can explain me how to solve that
> > problem?

>
> > Thanks in advance for your help,
> > Stani.

>
> you can open it and edit it with the Winrar program i believe.
> Located athttp://www.rarlabs.com/
> You should be able to open the jar file and edit its contents.


Im sorry, i had a misunderstanding. Disregard that last message.

 
Reply With Quote
 
stanislav.tomic@gmail.com
Guest
Posts: n/a
 
      08-17-2007
For example:

|-MyJAR.jar (containing my classes)
|-lib (containing my libraries, for example databes driver)
|-properties (containing my properties-file)

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-17-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
...
>I have a question concerning properties-files in Java.
>
>Writing in a properties-file and reading out of the file is working as
>long as I don't put my files in a JAR.


The best approach to user here, is to treat the
properties file in the jar as simply an 'initial'
properties file.

Check in "user.home"/our/backward/domain/
for the properties file. If it is not there, read it
from out of the jar, and write it to there.

Proceed loading the property file from the
sub-directory of user.home.

Using this scheme, you can also offer a
'revert properties to defaults' option in the
GUI, by simply retoring them from unchanged
version in the Jar.

But no, attempts to *edit* or *update* the actual
resource in the Jar file will probably fail, or end
in a very fragile application.

>The adventureous part of the programm is that I'm trying to make an
>application which should be able to remember user-settings (write
>values in properties-file) and load them (read out values of
>properties-file) when started next time.


Here is an example of storing user preferences.
<http://www.physci.org/jws/#ps>
It makes use of the web start API's PersistenceService
to do the same basic thing I described above, but for a
sandboxed app. launched using web start (and with no
specific '.properties' file to begin with).

>...(The user just has to unzip a ZIP-archive, which includes
>a folder with the necessary libraries and a JAR-file with my classes.)


'Tut-tut' - use web start for the launch - much easier
for the end-user.

HTH

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200708/1

 
Reply With Quote
 
stanislav.tomic@gmail.com
Guest
Posts: n/a
 
      08-17-2007
Thank you Andrew,

I will try that out. That sounds good.

Will other applications be able to access the properties-file in the
subfolder? Is there a way of limiting the access to the properties-
file only to my application?

You are right. I'll use webstart in the second development version. In
the first I'm forced to use an clientbased application.

Thanks again,
Stani.

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-17-2007
(E-Mail Removed) wrote:
...
>You are right. I'll use webstart in the second development version. In
>the first I'm forced to use an clientbased application.


What does a 'clientbased application' mean where
you come from? It means little to me.

If you are speaking of a desk-top application with
a GUI, then that is what web start was meant to
launch. Did you actually try the launch link
available at that web page anchor I put earlier?
You can see it on-screen. Please try the
launch link, and report your experiences.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via http://www.javakb.com

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      08-17-2007
(E-Mail Removed) wrote:
> Will other applications be able to access the properties-file in the
> subfolder? Is there a way of limiting the access to the properties-
> file only to my application?


No.

It's the customer's computer, not yours.

--
Lew
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-17-2007
Lew wrote:
>(E-Mail Removed) wrote:
>> Will other applications be able to access the properties-file in the
>> subfolder? Is there a way of limiting the access to the properties-
>> file only to my application?

>
>No.
>
>It's the customer's computer, not yours.


Actually, if using the web start PS, apps. are limited to
'addresses' based upon the JNLP codebase*, so they can
corrupt and mess up files for apps. from the same
codebase, but no other ones**.

<http://java.sun.com/javase/6/docs/jr...ceService.html
>

* "An application is only allowed to access data stored with a
URL that is based on its codebase. For example, given the
codebase http://www.mysite.com/apps/App1/, the application
would be allowed to access the data at the associated URLs:

http://www.mysite.com/apps/App1/
http://www.mysite.com/apps/
http://www.mysite.com/
This scheme allows sharing of data between different applications
from the same host. "

The first method I outlined, using something that was
supposed to represent the package name or similar of the
main() class of the app., as the sub-directory, is a 'good bet'
way to avoid name collisions with files written by other
applications. Put them in the root of user.home, at your own
risk, but nothing will save them from intentional sabotage.

** Of course, the user or their Sys. Admin., can do pretty
much the heck what they want, including relocating the
entire cache, or uninstalling parts, or all of an app.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200708/1

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
*WITHOUT* using: ValidateRequest="False" for the whole page (or my whole site).... \A_Michigan_User\ ASP .Net 2 08-21-2006 02:13 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM



Advertisments