Your resource path starts with a /
and is therefore an absolute path. If you want the resource path to be relative you have to omit the first /
.
From the Javadoc of Class.getResource(String name)
:
If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
Otherwise, the absolute name is of the following form: modified_package_name/name where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').
A relative path is relative to the path of the class returned by getClass()
.
An example:
package org.example;
public class MyClass {
public void foo() {
getClass().getResource("tut01/shaders/vertex_shader.glsl");
}
}
Let's assume the compiler writes the compiled class file to /home/my-project/bin/org/example/MyClass.class
.
getClass().getResource("tut01/shaders/vertex_shader.glsl")
would then look for the file in /home/my-project/bin/org/example/tut01/shaders/vertex_shader.glsl
.