When executed via the jar, I get a sensible URL path to the images.
When run from Eclipse it is null. This makes no sense as the relative
path from the codebase to the images hasn't changed since moving the
source code. It doesn't feel like a coding error as I've used my image
loading utility classes, numerous jars, Ant build files etc in loads
and loads of projects with no problems. This feels like an Eclipse
problem? Simply moving the folder in which the source is stored has
messed things up, but only when launching from Eclipse.
> Before getting resource as stream execute get resource and display the
> URL of the resource to make sure it is getting loaded from where you
[quoted text clipped - 3 lines]
> opalpa@gmail.com
> http://opalpa.info/
JavaEnquirer - 12 Oct 2006 15:20 GMT
Some more info if anyone's interested. When I execute my application
from within Eclipse the location of the class files as determined by
themselves is the same regardless of where the source is stored as I
expected. Why should moving the source affect get resource as stream?
Class objClass = MyClass.class;
ProtectionDomain pdomain = objClass.getProtectionDomain() ;
CodeSource codeSource = pdomain.getCodeSource() ;
URL codeLocation = codeSource.getLocation() ;
System.out.println("WHERE AM I: "+codeLocation);
JavaEnquirer - 12 Oct 2006 15:34 GMT
PROBLEM SOLVED, though not quite understanding how:
Project - Properties - Order and Export
Ranking the my four source folders from lowest level to highest seems
to have worked e.g.
MyProject/src/dev
MyProject/src/test
MyProject/src
MyProject
opalpa opalpa@gmail.com http://opalpa.info - 12 Oct 2006 15:44 GMT
I prefer NetBeans to Eclipse. NetBeans has never messed up a project.
Eclipse has, in the five times or so I've used it, always messed up
whatever project I imported.
opalpa
opalpa@gmail.com
http://opalpa.info/
JavaEnquirer - 12 Oct 2006 15:52 GMT
Cheers opalpa, thank you for your input.
> I prefer NetBeans to Eclipse. NetBeans has never messed up a project.
> Eclipse has, in the five times or so I've used it, always messed up
[quoted text clipped - 3 lines]
> opalpa@gmail.com
> http://opalpa.info/
opalpa opalpa@gmail.com http://opalpa.info - 12 Oct 2006 15:41 GMT
getResource and getResourceAsStream have rules for looking. These
rules are more encompasing then the classes' directories. For example
say you add getResource() somewhere in your code but neglect to add
copy command to your build. You might test your code and the resource
will load but it will get picked up from source tree which you didn't
expect.
Can you revert to previous location of source tree and see what URL you
get from getResource()?
I reckon the key questions are: what is eclipse running exactly and
what are the differences in what it is running from when you run app
independelty? And is there a difference in the classloader (which I
believe defines the rules for where getResource searches)?
opalpa
opalpa@gmail.com
http://opalpa.info/