In my project I access the folder that is in /src/main/ressources/Mylib in eclipse it works well without any problem, but when i export the project into .jar file it does not work.
The line of code that bug:
File fi = new File(Testp.class.getClassLoader().getResource("Mylib/").getFile()); and it gives this bug:
Exception in thread "main" java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61) Caused by: java.lang.NullPointerException at com.myproject.Testp.main(Testp.java:73) ... 5 more
getFile()method of URL does not return a valid filename. It just returns the path portion of a URL, with all of its escapes of special characters. The method name is like that because 25 years ago when the URL class was created, most URLs actually referred to physical files, either local or remote.getResourceAsStream()