In all probability, this is a classpath issue. getResourceAsStream in
the simplest case, uses classpath of the classloader to search for the
named resource. If we represent all files as (d,f) where "d+<system
dependent file path separator>+f" is the absolute path of the file and
you want to load "f" using getResourceAsStream(f) , "d" (which is a
directory) must be in the classpath of the classloader being used to
locate the resource.
Note that custom classloader implementations might change the
findResource implementation to do custom handling. In this case, you
will need to know how your classloader is locating(loading) resources .
Your code does not provide us with any information regarding your
classloader, classpath and directory structure. Hence it is difficult
for me to get more specific.
Abhijat
> hi
> i m using JBuilderX... the problem i m facing is very basic yet i
[quoted text clipped - 22 lines]
>
> Thanks a lot
Roedy Green - 13 Oct 2005 01:42 GMT
> ClassLoader cl = ResourceManager.class.getClassLoader();
>> return cl.getResourceAsStream(xml_file);
I think in your jar you need a resource named something like this:
com/bms/rm/xyz.XML
I would need to know ResourceManager's full class name to give it to
you precisely.
you can also shorten that to:
ResourceManger.class.getResourceAsStream();

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
> hi
> i m using JBuilderX... the problem i m facing is very basic yet i
[quoted text clipped - 22 lines]
>
> Thanks a lot
I can see that, as you say, the code is fine, except it's not working... :)
If the resource is on the classpath, you'll want to think about prefixing
the filename with a '/'. If, however, it's in a file outside the
classpath, as you indicate toward the end of your message, then have a
look at
http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileInputStream.html
instead.
You might want to consider renaming that 'another_class' before anyone
else notices it, too ;)

Signature
Ross Bamford - rosco@roscopeco.remove.co.uk
gbruno - 15 Nov 2005 03:14 GMT
Slightly off topic,
I have success showing rtf files in a JEditorPane loaded from a jar
I use the "stub" ResourceAnchor class, I'm not sure why,
but I was told it was necessary for webservices, which I dont use at present..
.
Here are some code scraps:
ClassLoader cl = ResourceAnchor.class.getClassLoader(); //webservices
version: // Get current classloader
RTFEditorKit rtf;
JEditorPane rtfeditor;
..
rtf = new RTFEditorKit();
rtfeditor = new JEditorPane();
rtfeditor.setEditorKit(rtf);
rtfeditor.setBackground(Color.white);
rtfeditor.setEditable(true);
rtfeditor.setMinimumSize(new Dimension(42, 42));
Insets i = new Insets(5, 5, 5, 21); // draw to fill the entire component
// some tinkering with margins, which is why Editable is set true (?)
rtfeditor.setMargin(i);
..
String ozall = docdir + rtfname; // "doc/somename.rtf" someone said
"dont use root"
..
InputStream in = cl.getResourceAsStream(ozall); // get the rtf files
from the jar
..
rtf.read(in, rtfeditor.getDocument(), 0);
[not so lucky attempting to show pdf in java, so for that I spawn an external
viewer]
cheers
gbruno
ps I havnt tried this remotely yet,

Signature
gbruno
http://gbruno2.blogspot.com/