ok well I have added this to the mainfest file and all my streams return as null.
I just use at the moment:
"Resources/Graphics/image1.gif"
and open this with getSystemResourceAsStream this seems to work from the same jar
if stream works and .getResource() doesn't on same directory structure then you resource.jar isn't on classpath. Check what's inside manifest file of main.jar ... it should be something like Class-Path: resources.jar.
If you want to be sure if your resources.jar is on classpath for testing put some empty class into it, like Test.class and just try to make a new inst
ance of it in your main app:
Test test = new Test(); ... it will fail if resources.jar isn't on classpath.
edit: of course, add jar to class path when compileing
ok, here is complete example

ResourcesInJarTest.java:
1 2 3 4 5 6 7 8
| public class ResourcesInJarTest { public static void main(String args[]) { Test test = new Test(); System.out.println("main"); } } |
Test.java:
1 2 3 4 5
| public class Test { public Test() { System.out.println("outside"); } } |
manifest.mf:
1 2 3
| Manifest-Version: 1.0 Main-Class: ResourcesInJarTest Class-Path: /test.jar |
(note extra line at the end)
compile and run:
javac Test.java
jar -cfv test.jar Test.class
javac ResourcesInJarTest.java -cp test.jar
jar -cfvm main.jar manifest.mf ResourcesInJarTest.class
java -jar main.jar