Java – where does Maven search for log4j Properties file?

I am using log4j with Maven to face problems I have a properties file, log4j Properties, I put this file in the POM. Net where the project is stored XML on the same path

POM xml

<dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
        <scope>test</scope>
</dependency>

I used log4j in my code, which is located in the test folder

code

package com.paras.automationtest;

import org.apache.log4j.*;
import org.junit.Test;

public class AppTest
{
    @Test
    public void testLogger(){
   //PropertyConfigurator.configure("C:\\Users\\Desktop\\AutomationTest\\log4j.properties");
    Logger log = Logger.getLogger("parasLogger");
    log.debug("Hello,World!");
   }
}

I want to know how Maven recognizes log4j Where is the properties file located?

In the above scenario, if I run the command MVN test, it will issue a warning. Please see the screenshot below for the warning message

So as a workaround, I provided log4j Properties I have used the following:

PropertyConfigurator.configure("C:\\Users\\Desktop\\AutomationTest\\log4j.properties")

Is it necessary to use the above line of code, or is there a maven to find log4j Any specific directory for the properties file?

Solution

The file needs to enter Src / main / resources / or Src / test / resources / (if only unit testing is required)

Longer explanation: Maven splits the Java classpath into source code and resources (non Java things, such as property files, images, etc.) The main reason for this is that Maven can filter resources for you and make them more secure. They put resources in different folders from the source

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>