question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getResource with absolute resource name is not working in native image

See original GitHub issue

Describe the bug Absolute resource names are not found in native images (with beginning ‘/’)

Expected behavior Absolute resource names should be found

To Reproduce Steps to reproduce the behavior:

Create any Jax-rs resource and add a property file.

@Path("jobs")
@ApplicationScoped
public class JobResource {

    @GET
    @Path("/simple-job")
    @Produces(MediaType.APPLICATION_JSON)
    public SimpleResponse simpleJob(@DefaultValue("World") @QueryParam("name") String name) throws IOException {
        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        String propteryFile = "/org/jobrunr/examples/webapp/api/test.properties";
        final URL resource1 = contextClassLoader.getResource(propteryFile);
        System.out.println("Property file exists: " + (resource1 != null));

        String propteryFile2 = "org/jobrunr/examples/webapp/api/test.properties";
        final URL resource2 = contextClassLoader.getResource(propteryFile2);
        System.out.println("Property file exists: " + (resource2 != null));

        return new SimpleResponse("Job Enqueued");
    }
}

In JVM mode the output is as follows: Property file exists: true Property file exists: true

In native mode the output is as follows: Property file exists: false Property file exists: true

Unless I don’t understand the spec correctly, I think resources with beginning ‘/’ should be handled as absolute resources: https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-

Configuration Pom.xml quarkus build config:

                    <plugin>
                        <groupId>io.quarkus</groupId>
                        <artifactId>quarkus-maven-plugin</artifactId>
                        <version>${quarkus-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                                <configuration>
                                    <enableHttpUrlHandler>true</enableHttpUrlHandler>
                                    <additionalBuildArgs>--allow-incomplete-classpath,-H:IncludeResources=*/*.properties$,-H:Log=registerResource:verbose</additionalBuildArgs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

Environment (please complete the following information):

  • Output of uname -a or ver: Linux rdehuyss-laptop 5.3.0-45-generic #37-Ubuntu SMP Thu Mar 26 20:41:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: openjdk version “11.0.7” 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu219.10) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu219.10, mixed mode, sharing)
  • GraalVM version (if different from Java): graalvm-ce-java8-20.0.0
  • Quarkus version or git rev: 15.1
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.1 Maven home: /usr/share/maven Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, version: “5.3.0-45-generic”, arch: “amd64”, family: “unix”

Additional context (Add any other context about the problem here.)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
geoandcommented, Jun 19, 2020

Yeah, we should address that

1reaction
rdehuysscommented, Jun 19, 2020

Yes - my mistake - doing further testing to find root cause.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get absolute path to file in /resources folder of your ...
The proper way that actually works: URL resource = YourClass.class.getResource("abc"); Paths.get(resource.toURI()).toFile();.
Read more >
Accessing Resources in Native Images - GraalVM
Accessing Resources in Native Images. By default, the native-image tool will not integrate any of the resources that are on the classpath into...
Read more >
171933 – GUI builder doesn't handle icon paths correctly
Setting an absolute path (using the Image Chooser, ... That would cause problems when trying to access via a resource name.
Read more >
How to Avoid the Java FileNotFoundException When Loading ...
txt the original code could not load this file as resources are not usually addressable as files on disk. The resource files are...
Read more >
ClassLoader (Java SE 9 & JDK 9 ) - Oracle Help Center
A class loader is an object that is responsible for loading classes. The class ClassLoader is an ... Returns the absolute path name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found