1

I am creating an application (hive udf) and for that I am creating an fat jar with all the dependencies. As this is going to be distributed over multiple nodes I need to pack my property files in jar as well.

Problem One of the function I am calling from another jar needs a parameter, a property file path. I have packed this property file inside jar. and passing just the name. However, it's complaining that file not found.

Code:

  c = new ABC("classification.props");

Function inside ABC class that read the property file

public static Properties getProperties(String propFile) {
    Properties props = new Properties();

    try {
        props.load(new FileInputStream(propFile));
        return props;
    } catch (IOException var3) {
        var3.printStackTrace();

    }
}

This ABC is coming from another jar. however I am creating a fat jar so shouldn't matter. classification.props is in the root folder of application.

Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137

1 Answers1

0

The getProperties method is looking for a file on the filesystem. That's not where your file is -- your file is in the JAR.

If you can change the getProperties` method, you can tell it to read the file as a class path resource instead.

How do I load a file from resource folder?

If you can't modify the getProperties method, you can copy the properties to the filesystem (load it as a class path resource using the technique in the linked answer, and then write to to a temp directory).

dnault
  • 8,340
  • 1
  • 34
  • 53