>>Thanks to all who answered. I got it.
>
> Could you post the code please?
>>> Thanks to all who answered. I got it.
>>
[quoted text clipped - 14 lines]
>
>
Of course you could replace "App.class" by
app.getClass().getName() + ".class"

Signature
Gruesse Roman
> Here a stand-alone example:
>
[quoted text clipped - 8 lines]
> }
> }
This code doesn't work. Or rather, it only works if your application is
composed of loose class files, but obviously isn't (or, at least,
hopefully isn't!) the case when you deploy the application.
I wrote a very complete and detailed answer to this question some time
ago. It's temporarily available in Word format at the following rather
ugly URL:
> http://www.javamoderator.org/Java%20White%20Papers/05%20%2D%20Miscellaneous/Find
ing%20Application%20Intrinsic%20Data.doc

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Roedy Green - 19 Dec 2005 01:21 GMT
>> http://www.javamoderator.org/Java%20White%20Papers/05%20%2D%20Miscellaneous/Find
ing%20Application%20Intrinsic%20Data.doc
IF you want I could format that as HTML and with an attribution add it
as http://mindprod.com/jgloss/intrinsicdata.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Chris Smith - 19 Dec 2005 04:26 GMT
> IF you want I could format that as HTML and with an attribution add it
> as http://mindprod.com/jgloss/intrinsicdata.html
In this case I have to say no. I wrote that on my employer's time, and
our plan was to collect a lot of similar documents, convert them to PDF
in a similar format, and place them on MindIQ's web site to lure Java
programmers' search engines in hopes that they'd see our commercial
training courses. That plan isn't actually progressing, but I can't
just give away content that technically belongs to MindIQ.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jean-Francois Briere - 19 Dec 2005 08:21 GMT
>> app.getClass().getResource("App.class")
> This code doesn't work. Or rather, it only works if your application is
> composed of loose class files
Actually the code works for either loose class files or class files
within jar files.
Regards
David Segall - 19 Dec 2005 15:12 GMT
>> Here a stand-alone example:
>>
[quoted text clipped - 17 lines]
>
>> http://www.javamoderator.org/Java%20White%20Papers/05%20%2D%20Miscellaneous/Find
ing%20Application%20Intrinsic%20Data.doc
Thank you for the code in technique #5 which returns the appropriately
formatted directory name that I would expect.
Could you explain why you say using .getResource() does not work? The
raw result seems similar to that obtained from
getProtectionDomain().getCodeSource() and I don't see why some similar
post-processing would not yield the same directory name.
Chris Smith - 19 Dec 2005 16:07 GMT
> Could you explain why you say using .getResource() does not work? The
> raw result seems similar to that obtained from
> getProtectionDomain().getCodeSource() and I don't see why some similar
> post-processing would not yield the same directory name.
Well, for one thing, getResource() is not guaranteed to work on a class
file in the first place. But in practice, it does work; so that's not
the most important problem.
The real problem is that the original code just doesn't work for code
that's packaged in a JAR file. getResource() returns a URL with the
"jar" scheme, and calling "getPath" on that URL doesn't do what you
want. getCodeSource(), on the other hand, will return a file-scheme URL
pointing to the JAR file itself. That is what you want.
getCodeSource() is also more convenient even for loose classes, if they
are in packages. getResource() returns a path that points deep into the
package structure. getCodeSource() points to the root of that
structure, which is almost certainly what you wanted in the first place.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
David Segall - 19 Dec 2005 16:40 GMT
>> Could you explain why you say using .getResource() does not work? The
>> raw result seems similar to that obtained from
[quoted text clipped - 15 lines]
>package structure. getCodeSource() points to the root of that
>structure, which is almost certainly what you wanted in the first place.
Thanks Chris. I'm convinced. I think it would be worthwhile to add
this explanation to your essay since getResource() is most frequently
proposed as the solution to the problem.
>>>Thanks to all who answered. I got it.
>>
[quoted text clipped - 14 lines]
>
>
Thanks Roman. On my system that returns
"file:/C:/Program%20Files/App/App.jar!/App.class". I was hoping for
something that needed less post-processing to yield
"C:Program Files/App".