Where is the JAR currently being executed?

M

Mark Space

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

Thomas Kellerer

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
 
M

Mark Space

Thomas said:
Mark Space wrote on 17.03.2007 16:44:

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

Thomas Kellerer

Mark Space wrote on 17.03.2007 17:42:
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().
 
J

Joshua Cranmer

Mark said:
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.
 
F

fy4.net

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
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top