Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Accessing the name of the CLASS/JAR file invoked

Thread view: 
AndrewTK - 08 Oct 2007 11:24 GMT
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 - 08 Oct 2007 12:13 GMT
..
> 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 - 08 Oct 2007 13:30 GMT
> > I would like to be able to extract them ..
>
[quoted text clipped - 3 lines]
>
> 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 - 08 Oct 2007 14:12 GMT
..
>..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.

Signature

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

Patricia Shanahan - 08 Oct 2007 15:45 GMT
> .
>> ..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 - 08 Oct 2007 16:24 GMT
>> .
>>> ..kind of like a self-extracting archive ..
[quoted text clipped - 6 lines]
>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.

Signature

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

AndrewTK - 09 Oct 2007 15:52 GMT
> 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 - 10 Oct 2007 05:38 GMT
>> Considering the %age of desk-top. apps that *can*
>> be deployed using web start, I'd prefer to deal with
[quoted text clipped - 6 lines]
>
> 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 - 12 Oct 2007 03:29 GMT
>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.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 12 Oct 2007 07:14 GMT
>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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.