In general, your solution should work temporarily.
What are these provisions? Make sure your resource folder is in your classpath. If you are not sure, add it to the -cp flag passed to java when your program is running, or if you use Eclipse or some other IDE, make sure it is listed as a member of the class path for this project,
Next up, https://stackoverflow.com/a/414829/ Although the way you use the getResourceAsStream () method is valid (including / at the beginning of the file name causes the class resource loader to defer to the ClassLoader method), it may be less confusing to use ClassLoader directly. Another good example can be found here .
So firstly, make sure your resource folder is explicitly part of the class path. Secondly, prefer the following construction to search for a resource:
InputStream stream= this.class.getClassLoader().getResourceAsStream("lutum.jks");
Note the missing / from file name. This is due to the fact that ClassLoader will automatically start searching in the βroot of the projectβ, and the slash is likely to cause problems (if, for example, you deploy to JBoss or Tomcat, which are likely to be interpreted as a class loader as the path of the relative file system relative ways).
Hope this helps. If not, please comment on more details about your project, and I will change my answer accordingly.
Programmerdan
source share