Re: how to prevent a jar executed only once in a machine
- From: "Steve W. Jackson" <stevewjackson@xxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 15:38:44 -0500
In article <1151698594.337069.99380@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"John_Woo" <john_woo@xxxxxxxxxx> wrote:
[ snip ]
Hi, Steve
It's appreciated what suggested.
1 more question:
if the created file is still, and permission changed to Readonly, then
no way to lock it.
so,
1. how to set to write in my app?
2. if I want to update timestamp to a file which is already existed in
my.jar, can u tell how to write this file <not outside my.jar>?
--
Thanks lots.
John
I'm not quite sure I understand the question.
If the objective is to prevent the same user from running the program,
you shouldn't want to use a read-only file. Simply create a new file
with a name unique to your application, open it for output, and get an
exclusive lock. Any failure to get the lock means it's locked by
another instance of your application.
I suppose you could use an existing file, opened with a FileInputStream
in a fashion similar to what I described. The FileInputStream class has
the getChannel() method to return a FileChannel, and it's that class
which provides the tryLock() method used to get an exclusive lock on the
file.
Writing to a file inside your own jar file is another matter altogether
and not something to be undertaken lightly. Manipulating jar file
contents is complex enough. But doing so when your application is
running from the jar is something else entirely -- and I wouldn't have
the first idea whether it's really even possible.
= Steve =
--
Steve W. Jackson
Montgomery, Alabama
.
- References:
- how to prevent a jar executed only once in a machine
- From: John_Woo
- Re: how to prevent a jar executed only once in a machine
- From: Steve W. Jackson
- Re: how to prevent a jar executed only once in a machine
- From: John_Woo
- Re: how to prevent a jar executed only once in a machine
- From: Steve W. Jackson
- Re: how to prevent a jar executed only once in a machine
- From: John_Woo
- how to prevent a jar executed only once in a machine
- Prev by Date: Re: how to prevent a jar executed only once in a machine
- Next by Date: how to reformat the currency?
- Previous by thread: Re: how to prevent a jar executed only once in a machine
- Next by thread: Re: how to prevent a jar executed only once in a machine
- Index(es):