3

I created a Java project that contains three configuration file

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

I put these three files into a resource folder.

Then I created a jar file of my project. This jar file is added to another project. It isn't able to find the correct location of the configuration files.

My file structure:

alt text

Thanks


2 Answers 2

3

you can use it like.

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

than if you add this jar to another project you will be able to access it.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks.i try but it return null value.URL url= this.getClass().getResource("resources/log4j.xml");
@sam don't use this, try ClassFromWhichYouAreACcessingTheseFiles.class.getResources("/resources/log4j.properties");
1

If your config files end up in the WEB-INF/classes folder

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

otherwise it include the "package-path" from the ClassFromWhichYouAreACcessingTheseFiles

1 Comment

thanks,it works.it's required to my jar file contains resources folder.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.