I have a better approach to solve this
My project structure is :- You can see there is no property file in this project structure
package com.main;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Run {
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream stream = loader.getResourceAsStream("config.properties");
prop.load(stream);
System.out.println(prop.getProperty("name"));
}
}
Now place the property file within the same folder where you have exported the runnable jar file.
For this approach you don't need to create a property file in eclipse you just have to create a property file where you export the runnable jar and remember don't give the path of a property file, write only the property file name like this
InputStream stream = loader.getResourceAsStream("config.properties");