Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j: Could not find resource

I have this log4j.properties

in this path:

❯ ls -l /Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties                                                         [15:54:01]
-rw-r--r--  1 eladb  eng  853 Jun 27 15:41 /Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties

however, when I run my application I see in the console:

log4j: Trying to find [/Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@4e25154f.
log4j: Trying to find [/Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties] using sun.misc.Launcher$AppClassLoader@4e25154f class loader.
log4j: Trying to find [/Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties] using ClassLoader.getSystemResource().

log4j: Could not find resource: [/Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties].

here is my code:

public class DeviceRepositoryFromJsonFile implements DeviceRepository {

    final static Logger logger = Logger.getLogger(DeviceRepositoryFromJsonFile.class);


    public DeviceRepositoryFromJsonFile() {
        BasicConfigurator.configure();

        filePath = Constants.devicesJsonPath;
        jsonFileHandlerDevice = new JsonFileHandler<>(filePath);
        devices = fetchFromFile();
    }

I'm using gradle

what am i missing?

like image 842
Elad Benda2 Avatar asked Jun 27 '16 12:06

Elad Benda2


1 Answers

I ran into this issue today myself.

All you need to do is use the file:// protocol before putting the path of the properties file for log4j to read.

So, your path will something be like

-Dlog4j.configuration=file:///Users/eladb/workspaceQa/MobileAutomationWebService/web-services/src/main/resources/log4j.properties

Hope it helps someone else by pointing them to the correct solution quickly :)

like image 163
Abhinav Avatar answered Sep 28 '22 07:09

Abhinav