My goal is to create an executable jar from Eclipse. I have an Eclipse project which runs fine with the structure below.
My Eclipse project
src/main/java
-com.main
->MyClass
src/main/resources
->MyProps.properties
MyClass
is able to access MyProps.properties
file successfully.
After I export the Eclipse project and create a runnable jar then my jar structure is like below.
MyJar.jar
-com.main
->MyClass
-resources
->MyProps.properties
When I run the jar file it fails to access the properties file throwing a NullPointerExeception
.
My code
InputStream input = MyClass.class.getClassLoader()
.getResourceAsStream("resources/MyProps.properties");
When I export my project as an executable jar file, I cannot access MyProps.properties
anymore.
Can someone help me please?