Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Where is the JAR currently being executed?

Reply
Thread Tools

Where is the JAR currently being executed?

 
 
Mark Space
Guest
Posts: n/a
 
      03-17-2007
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?
 
Reply With Quote
 
 
 
 
Thomas Kellerer
Guest
Posts: n/a
 
      03-17-2007


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


getClass().getResourceAsStream()

Thomas
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      03-17-2007
Thomas Kellerer wrote:
>
>
> Mark Space wrote on 17.03.2007 16:44:
>>
>> 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?

>
> 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"); ?
 
Reply With Quote
 
Thomas Kellerer
Guest
Posts: n/a
 
      03-17-2007


Mark Space wrote on 17.03.2007 17:42:
> Thomas Kellerer wrote:
>>
>>
>> Mark Space wrote on 17.03.2007 16:44:
>>>
>>> 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?

>>
>> getClass().getResourceAsStream()

>
> 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().



 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      03-17-2007
Mark Space wrote:
> Thomas Kellerer wrote:
>>
>>
>> Mark Space wrote on 17.03.2007 16:44:
>>>
>>> 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?

>>
>> 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"); ?


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.
 
Reply With Quote
 
fy4.net@gmail.com
Guest
Posts: n/a
 
      03-18-2007
On 3月17日, 下午11时44分, Mark Space <marksp...@sbc..global.net> wrote:
> 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?


More see here!
http://www.flash50.com/index.php

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      03-18-2007
On Mar 18, 7:26 pm, "(E-Mail Removed)" <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to print out the currently used JAR file path to verify itis using right JAR? Arne Vajh鴍 Java 0 11-06-2011 10:42 PM
Re: How to print out the currently used JAR file path to verify itis using right JAR? markspace Java 2 10-07-2011 06:17 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM



Advertisments