Before building the project, the path to the resources of such "src / main / resources /", after the assembly, this path no longer works, because in the jar file the resources are at the very beginning. Folders src, main and resources anymore. How to make the path work both before assembly and after?

  • If there is no way, then how can it work? - Roman C

1 answer 1

You are accessing resources incorrectly. The src/main/resources/ directory is the root for the resource files in the source code. Resources should not be accessed as regular files, but with Class#getResourceAsStream() relative to the classpath. For example, if you have src/main/resources/com/example/myprogram/file.properties then the path to it in your code will be src/main/resources/com/example/myprogram/file.properties /com/example/myprogram/file.properties .

  • It is clear, thank you - Sanek Homa