I've used new URL(URL context, String spec) in the flowing scenario (native image):
URL url1 = ClassLoader.getSystemResource("r1.txt");
URL url2 = new URL(url1, "r2.txt");
System.out.println(new Scanner(url2.openStream(), "UTF-8").useDelimiter("\\A").next());
line 3 prints content of the resource pointed by url1, but must print the content of the resource pointed by url2 .