Accessing the name of the CLASS/JAR file invoked  
Author Message
AndrewTK





PostPosted: 2007-10-8 18:24:00 Top

java-programmer, Accessing the name of the CLASS/JAR file invoked Hello,

I am trying to pack all my files into a JAR - this includes CLASS
files and other textual files such as help, std configs, etc.

I would like to be able to extract them from the Java app straight out
of the JAR - and for this I need to know what the name of the JAR file
invoked was (it might have been renamed for X reasons)

Is there any sure way to do this? (the alternative is to have an
external file to contain said data, but I want to know if a way to
have everything self-contained exists, first)

Thanks,

Andrew

 
Andrew Thompson





PostPosted: 2007-10-8 19:13:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked On Oct 8, 8:24 pm, AndrewTK <email***@***.com> wrote:
..
> I am trying to pack all my files into a JAR - this includes CLASS
> files and other textual files such as help, std configs, etc.

Good idea.

> I would like to be able to extract them ..

Do you mean, 'access the resource from within
the jar', or 'extract each resource to the
local file-system'?

For the former, see Class.getResource("path/name").

Andrew T.

 
AndrewTK





PostPosted: 2007-10-8 20:30:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked On Oct 8, 12:13 pm, Andrew Thompson <email***@***.com> wrote:
> > I would like to be able to extract them ..
>
> Do you mean, 'access the resource from within
> the jar', or 'extract each resource to the
> local file-system'?
>
> For the former, see Class.getResource("path/name").

Thanks for that - looks like it does what I was looking for, will
test.

However I am trying to do both actually - makes kind of like a self-
extracting archive etc etc.

Cheers,

Andrew K

 
 
Andrew Thompson





PostPosted: 2007-10-8 21:13:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked AndrewTK wrote:
.
>..kind of like a self-extracting archive ..

My advice on that is "don't". For good deployment
options, see Java web start. Here are some examples.
<http://www.physci.org/jws/>

Whether these applications are extracted to class files,
or kept locked up in the original jars (at the decision of
the end user, or their sys-admin.) I neither know nor
care.

I use Class.getResource() and it provides an URL pointing
to the resource in question, whether it is still on the
host site (lazy downloads) or cached on the file-system
(jar'd or loose).

Best of all, if I upload a new Jar (or Jar's - it is easy
to break up JWS apps. into small easy 'chunks') the
end-user gets the new jars on next application start-up.

Why p*ss about with self-extracting archives when you
can have all that, and more*?

* See the examples, for some other neat desktop
integration and 'trimmings' provided with JWS launch.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1

 
 
Patricia Shanahan





PostPosted: 2007-10-8 22:45:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked Andrew Thompson wrote:
> AndrewTK wrote:
> .
>> ..kind of like a self-extracting archive ..
>
> My advice on that is "don't". For good deployment
> options, see Java web start. Here are some examples.
> <http://www.physci.org/jws/>
...

No matter how good an option Java web start is for programs that can use
it, it is not a universal solution. See my case of a batch program that
needs to run with no user interaction and no GUI.

I am VERY interested in alternatives that allow distribution of a single
JAR, even if they do involve a bit more coding.

Patricia
 
 
Andrew Thompson





PostPosted: 2007-10-8 23:25:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked Patricia Shanahan wrote:
>> .
>>> ..kind of like a self-extracting archive ..
>>
>> My advice on that is "don't". For good deployment
>> options, see Java web start. Here are some examples.
>> <http://www.physci.org/jws/>
>...
>
>No matter how good an option Java web start is ..for programs that can use
>it, it is not a universal solution.

Considering the %age of desk-top. apps that *can*
be deployed using web start, I'd prefer to deal with
other cases as they 'arise'. Or to put that more
specifically, when the OP replies (usually in irritation)
that they 'have already considered web start'* and
it is no good because.. (insert reasons here).

* Often, from some earlier discussion I'd had with
them, but entirely forgotten.

>..See my case of a batch program that
>needs to run with no user interaction and no GUI.

Yes, that was a good example, but that was *your*
use-case. I would like to hear it from the OP, what
*their* use-case is.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1

 
 
AndrewTK





PostPosted: 2007-10-9 22:53:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked On Oct 8, 4:25 pm, "Andrew Thompson" <u32984@uwe> wrote:
> Considering the %age of desk-top. apps that *can*
> be deployed using web start, I'd prefer to deal with
> other cases as they 'arise'.

Well actually most of the time I'm dealing with server test apps. They
may or may not need GUIs, but they generally would run in the
background without. Not a requirement, but it would be good to know
that it can be done.

Patricia, what was your case/where is it located if I may peek?

This is mostly a learning experience project, so any input is good -
so if you do know of a way to find out what the name of the invoked
file is, twould be much appreciated as that's mainly what I'm after.

Ta muchly,

Andrew K

 
 
Patricia Shanahan





PostPosted: 2007-10-10 12:39:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked AndrewTK wrote:
> On Oct 8, 4:25 pm, "Andrew Thompson" <u32984@uwe> wrote:
>> Considering the %age of desk-top. apps that *can*
>> be deployed using web start, I'd prefer to deal with
>> other cases as they 'arise'.
>
> Well actually most of the time I'm dealing with server test apps. They
> may or may not need GUIs, but they generally would run in the
> background without. Not a requirement, but it would be good to know
> that it can be done.
>
> Patricia, what was your case/where is it located if I may peek?

It was discussed in a previous thread in this newsgroup. See
http://groups.google.com/group/comp.lang.java.programmer/msg/2fdc49fc5086d2eb

I have a simulation program that I use in my research. I am both
developer and the only end user. Each run is very simple - it reads an
XML parameter file and generates an XML report. The difficulty is that
individual runs can take several hours, and I frequently need to do
blocks of about a hundred runs.

I have various tools that build sets of parameter files and process the
results. Bulk runs are done on a grid computer, using a qmake utility
that acts like a parallel make, but pushes the tasks to the grid's run
queues. I am allowed to have up to 64 runs at any one time.

Obviously, this all has to be automated to be practical. I only look at
individual results if I see some anomaly in bulk reports that compare
results from a large set of runs. Normally, each run turns into a point
in each of a couple of charts.

Patricia
 
 
Roedy Green





PostPosted: 2007-10-12 10:30:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked On Mon, 08 Oct 2007 10:24:01 -0000, AndrewTK <email***@***.com>
wrote, quoted or indirectly quoted someone who said :

>I would like to be able to extract them from the Java app straight out
>of the JAR - and for this I need to know what the name of the JAR file
>invoked was (it might have been renamed for X reasons)

You don't need to know the name of the jar to extract data members.
See http://mindprod.com/jgloss/resource.html

If you need to know the name of the jar for some other reason, you
could look at the classpath in the System.Properties
see http://mindprod.com/jgloss/properties.html

Then examine each jar on the classpath to see if it contains your
stuff.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
 
Roedy Green





PostPosted: 2007-10-12 14:15:00 Top

java-programmer >> Accessing the name of the CLASS/JAR file invoked On Mon, 08 Oct 2007 10:24:01 -0000, AndrewTK <email***@***.com>
wrote, quoted or indirectly quoted someone who said :

>I would like to be able to extract them from the Java app straight out
>of the JAR

If you want to unpack jars and install files on the local hard disk,
use Java Web Start. Have a look how The Esperanto Traduiklo does this
with the Installer class. See
http://mindprod.com/products2.html#ESPER
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com