I've looked at all kinds of answers for this problem. None of them work.
I have the following code:
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ApplicationConfig {
private static Logger LOG;
private String appConfigFileLocation = "application.properties";
private Properties appConfig;
private static ApplicationConfig instance;
public static ApplicationConfig getInstance() {
if(instance == null) {
instance = new ApplicationConfig();
}
return instance;
}
private ApplicationConfig() {
LOG = LoggerFactory.getLogger(this.getClass().getSimpleName());
appConfig = new Properties();
try {
LOG.info("Reading config from " + appConfigFileLocation);
appConfig.load(ClassLoader.getSystemResourceAsStream(appConfigFileLocation));
LOG.info("Done reading config from " + appConfigFileLocation);
} catch (FileNotFoundException e) {
LOG.error("Encountered FileNotFoundException while reading configuration: " + e.getMessage());
throw new RuntimeException(e);
} catch (IOException e) {
LOG.error("Encountered IOException while reading configuration: " + e.getMessage());
throw new RuntimeException(e);
}
}
}
I created a JAR file. The JAR file has application.properties
at the root. I also copied the application.properties
file in /etc/hadoop/conf
and in the target/classes/
directory.
I use the hadoop jar
command to execute the code.
But I keep getting the error: java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:434)
Please help me at resolving this frustrating error!
Found the error.
hadoop jar
checks in the Hadoop classpath. Even though the file was there in the Hadoop classpath, it didn't have read permissions from the Hadoop user.
A simple sudo chmod a+r /etc/hadoop/conf/application.properties
did the trick!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.