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 / March 2007

Tip: Looking for answers? Try searching our database.

Where is the JAR currently being executed?

Thread view: 
Mark Space - 17 Mar 2007 16:44 GMT
Hi all, here's a basic question I haven't been able to find the answer to.

Let's say I'm executing a JAR from the command line from a location that
isn't in the CLASSPATH.  The JAR implements it's own classLoaders and
wants to use data in the JAR to construct some classes.  How does the
classLoader (or I guess any other method) locate the JAR file being
executed so it can load some resources?

OK, same question, but this time my JAR file is contained inside another
JAR file.  Now how do I find it?
Thomas Kellerer - 17 Mar 2007 17:17 GMT
Mark Space wrote on 17.03.2007 16:44:
> Hi all, here's a basic question I haven't been able to find the answer to.
>
[quoted text clipped - 3 lines]
> classLoader (or I guess any other method) locate the JAR file being
> executed so it can load some resources?

getClass().getResourceAsStream()

Thomas
Mark Space - 17 Mar 2007 17:42 GMT
> Mark Space wrote on 17.03.2007 16:44:
>>
[quoted text clipped - 5 lines]
>
> getClass().getResourceAsStream()

I was probably unclear with that last bit.  I mean resources
generically, not specificaly a Java Resource.

Let's say I want to muck with the class search order, loading classes
from my package space first from the current JAR.  Then defaulting to
the parent classLoader only if the class isn't found locally.

Hmm, is a class a resource?  I haven't actually tested this yet.

Can I getResourceX("/classes/MyPackage/subpackage/MyClass.class"); ?
Thomas Kellerer - 17 Mar 2007 18:07 GMT
Mark Space wrote on 17.03.2007 17:42:

>> Mark Space wrote on 17.03.2007 16:44:
>>>
[quoted text clipped - 8 lines]
> I was probably unclear with that last bit.  I mean resources
> generically, not specificaly a Java Resource.

What do you mean with "Java Resource"?

Any file in the .jar can be loaded using the stream returned by
getResourceAsStream().
Joshua Cranmer - 17 Mar 2007 18:10 GMT
>> Mark Space wrote on 17.03.2007 16:44:
>>>
[quoted text clipped - 16 lines]
>
> Can I getResourceX("/classes/MyPackage/subpackage/MyClass.class"); ?

Why don't you test it to find out? You could answer your own question.

I believe the answer is yes, although this is a spur-of-the-moment,
untested answer, whose validity should not be trusted.
fy4.net@gmail.com - 18 Mar 2007 09:26 GMT
> Hi all, here's a basic question I haven't been able to find the answer to.
>
[quoted text clipped - 6 lines]
> OK, same question, but this time my JAR file is contained inside another
> JAR file.  Now how do I find it?

More see here!
http://www.flash50.com/index.php
Andrew Thompson - 18 Mar 2007 10:09 GMT
On Mar 18, 7:26 pm, "fy4....@gmail.com" <fy4....@gmail.com> wrote:
..
> More see here!

Oh, more stupid messages.  I could pass the
first one off as you being an imbecile, but
this is becoming more like a concerted
spamming effort.

Andrew T.


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



©2008 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.