I can successfully load resources that are in some package of my src / dir in eclipse. Now I export the jar (right-click src, export, jar and save the default settings) and cannot load the resource in another eclipse project.
I create a resource path by specifying a class standing in the same package name:
URL out = getClass().getClassLoader().getResource(packageName(getClass())+"file.glsl"); // out is null when loaded from a jar!! protected static String packageName(Class<?> clazz){ return packageName(clazz.getPackage()); } protected static String packageName(Package p){ return c + p.getName().replace('.', c) + c; } protected static char c = File.separatorChar;
Do you see the wrong way? I tried:
- GetClass (). GetResource ()
- GetClass (). GetClassLoader (). GetResource ()
- GetClass (). GetClassLoader (). GetResourceAsStream ()
- Thread.currentThread (). GetContextClassLoader (). GetResource ()
- add / remove '/' char at the beginning of the package name
- using either '/', '\', or File.separatorChar, and even '.', all failed.
I checked that:
- jar contains the resource (jar content extension in the eclipse linked libraries project)
- packageName (getClass ()) + file name) returns the pure name: "\ org \ jzy3d \ plot3d \ rendering \ ddp \ algorithmms \ dual_peeling_init_vertex.glsl"
I infinitely extract zero: /
EDIT: screenshot and code to show that βthis should workβ

You can get this zpg eclipse project for SSCCE here
User class
public class User { public static void main(String[] args) { Loader pair = new Loader(SomeClass.class, "shade_vertex.glsl"); System.out.println("found:" + pair.getURL()); } }
Dynamically create a class using the new SomeClass (). getClass () produces the same result.
Loader
package com.pkg.loader; import java.io.File; import java.net.URL; public class Loader { public Loader(Class<?> c, String file) { this(packageName(c.getPackage()), file); } public Loader(Package p, String file) { this(packageName(p), file); } protected Loader(String pack, String file) { this.pack = pack; this.file = file; } public String getStringPath() { return pack+file; } public URL getURL() { URL out = Thread.currentThread().getContextClassLoader().getResource(getStringPath()); if(out==null) throw new RuntimeException("unable to find shader URL for :'"+getStringPath()+"'"); return out; } protected static String packageName(Class<?> clazz){ return packageName(clazz.getPackage()); } protected static String packageName(Package p){ return c + p.getName().replace('.', c) + c; } protected static char c = File.separatorChar; protected String pack; protected String file; }
Marker class
public class SomeClass {}
source share