getResource() and jar files?

K

Knute Johnson

If you have an application in a jar file and use getResource() to load
something, how do you get it to load something that isn't in the jar file?

Thanks,
 
L

Lothar Kimmeringer

Knute said:
If you have an application in a jar file and use getResource() to load
something, how do you get it to load something that isn't in the jar file?

getResource is looking into the places residing in the classpath.
If something is in the classpath it will be found. If it doesn't
it will not.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
K

Knute Johnson

Lothar said:
getResource is looking into the places residing in the classpath.
If something is in the classpath it will be found. If it doesn't
it will not.


Regards, Lothar

So say I have an app in a jar, test.jar. I set the classpath in
test.man to '.'. It still won't find my resource in the current
directory. Does the classpath have to be another jar file?

Thanks,
 
B

Brandon McCombs

Knute said:
So say I have an app in a jar, test.jar. I set the classpath in
test.man to '.'. It still won't find my resource in the current
directory. Does the classpath have to be another jar file?

Thanks,

Your MANIFEST.MF file in the JAR file should specify the classpath. What
is test.man in your example?? Build your JAR file with a MANIFEST.MF
that looks something like this:

Manifest-Version: 1.0
Main-Class: org/myorg/myapp/gui/MyApp
Class-Path: lib/myapp1.jar lib/myapp2.jar

Do not include an extra line after Class-Path. If you put your path as
another path entry it should work. Resources for a JAR file should be
inside the actual JAR file so everything is packaged into a single bundle.
 
K

Knute Johnson

Brandon said:
Resources for a JAR file should be
inside the actual JAR file so everything is packaged into a single bundle.

That's my question, can I have resources that are not in the jar? If
so, how do I reference them in the manifest file?
 
C

Chris Uppal

Knute said:
That's my question, can I have resources that are not in the jar? If
so, how do I reference them in the manifest file?

I'n curious. I don't know the answer to your questioni for sure, but why do
you suspect that it /should/ be possible ? Resources are loaded by
ClassLoaders, and ClassLoaders have nothing (in general) to do with the "local
file system".

-- chris
 
K

Knute Johnson

Chris said:
I'n curious. I don't know the answer to your questioni for sure, but why do
you suspect that it /should/ be possible ? Resources are loaded by
ClassLoaders, and ClassLoaders have nothing (in general) to do with the "local
file system".

-- chris

Because if the class isn't in a jar you can load resources from
anywhere. I just haven't been able to find a reference anywhere that
says you can't load them from sources other than jars if your app is in
a jar. I think you can still load resources from the net if your app is
in a jar.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top