log4j:找不到资源

时间:2016-06-27 12:59:58

标签: java macos logging log4j

我有log4j.properties

在这条道路上:

❯ 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

然而,当我运行我的应用程序时,我在控制台中看到:

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].

这是我的代码:

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();
    }

我正在使用gradle

我错过了什么?

2 个答案:

答案 0 :(得分:4)

我今天遇到了这个问题。

您需要做的就是使用file://协议,然后再将log4j的属性文件的路径读取。

所以,你的道路就像是

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

希望通过快速将他们指向正确的解决方案来帮助其他人:)

答案 1 :(得分:0)

确保服务器没有在根服务器文件夹中查找该文件夹