Problem trying to read resource files.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problem trying to read resource files.

John Smith
Hi, using Flink 1.8.0 and I have a Gradle project created using the cli util.

When running inside the IDE the below works perfectly fine...

ClassLoader classLoader = ClassLoader.getSystemClassLoader();
System.out.println("Config: " + classLoader.getResource(fileName).getFile());

But when Submitting the job using ./flink run my-fat.jar. It doesn't work.
I checked the jar and the file is in the root of the jar, but not in the classpath.

I have also attempted to print the content of the classpath using the below code. In the IDE the file show up in the classpath, once it is submitted as a job it does not appear.

    public static Collection<String> getResources(
        final Pattern pattern){
        final ArrayList<String> retval = new ArrayList<String>();
        final String classPath = System.getProperty("java.class.path", ".");
        final String[] classPathElements = classPath.split(System.getProperty("path.separator"));
        for(final String element : classPathElements){
            retval.addAll(getResources(element, pattern));
        }
        return retval;
    }