Good day. There is a config.properties file in the project resources. When building the project, IDE uploads the file to the WEB-INF/classes/ WAR file directory. And now the question directly: how to determine the path to the folder in which the application will be deployed? And where will the file be located?

The problem is that when you deploy an application (at least through the programming environment), all files are moved to the generated folder with what seems to be a random name. Therefore, even using the relative path from the server's home directory ( System.getPropertie("jboss.home.dir") ), the file cannot be found.

Is there any method to uniquely determine the location of deployed files?

  • Maybe there is, Only properties somehow load without this path. In general, it is assumed that in these applications the loading of any resources will be carried out without any knowledge of physical paths.1) stackoverflow.com/questions/3160691/… 2) stackoverflow.com/questions/2161054/… - Sergey
  • This is the method of searching for the relative path in the system I was looking for. I could not formulate the idea correctly (and therefore did not google it). Thank you so much, helped! Write the answer, I will note it: can someone help. - Janislav Kornev
  • I am not able to translate all this (by reference). Especially not understanding the intricacies of loading classes. - Sergey
  • @Sergey Then I will answer. Nevertheless thank you. - Janislav Kornev

1 answer 1

It is best to use ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); . Such a ClassLoader guaranteed to have access to all resources. When used, the relative path begins with the WEB-INF/classes/ your deployed application. The first / is not indicated here.