简体   繁体   中英

Classloader loading wrong log.properties file

I have EAR which contains multiple jars out of which two of the jar contains "log.properties"

For eg: In abc.jar, "log.properties" is in com.abc.test and in xyz.jar, "log.properties" is in com.xyz.test

In both the package we have logger implementation which load "log.properties" as this.getClass().getClassLoader().getResourceAsStream("log.properties");

Due to classloader which loads the other jar first it pickup his "log.properties"

I want to avoid this problem Any suggestions ?

Use ClassLoader.getResources(String name) and write code to filter out URLs that are not in the same package as the class. Place that code in a utility or resource manager class and use it everywhere in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM