How to get the correct path to the configuration file?

I created a Java project containing three configuration files

  • log4j.XML
  • QueueConfig.xml
  • rabbitmq.properties

I put these three files in a resource folder.

Then I created the jar file of my project. This jar file is added to another project. It cannot find the correct location of the configuration files.

My file structure:

alt text

thank


+3
source share
2 answers

You can use it as.

ClassFromWhichYouAreACcessingTheseFiles.class.getResources("resources/log4j.properties");

than if you add this jar to another project, you can access it.

+3
source

If your configuration files fall into the WEB-INF / classes folder

ClassFromWhichYouAreACcessingTheseFiles.class.getClassLoader().getResources("log4j.properties"); 

" " ClassFromWhichYouAreACcessingTheseFiles

+1

Source: https://habr.com/ru/post/1774496/


All Articles