Accessing the name of the CLASS/JAR file invoked

A

AndrewTK

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
 
A

Andrew Thompson

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

AndrewTK

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
 
A

Andrew Thompson

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
 
P

Patricia Shanahan

Andrew said:
AndrewTK wrote:
.

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
 
A

Andrew Thompson

Patricia said:
...

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
 
A

AndrewTK

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
 
P

Patricia Shanahan

AndrewTK said:
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
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top