I am currently writing a small Maven Java application in Netbeans using sl4fj and log4j2. I am not able to use the java property log4j.configurationFile
when deploying it in the production environment. Therefore i want log4j2 to search and find the property file within my project. I have googled around and tried, without luck, the following options;
Added the log4j2.xml to the src/main/resources folder and included it in the jar using the maven configuration (pom.xml). This actually does not include in in the classpath, but adds the xml to a location in the classpath.
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>com/reddipped/jsonlogger_2</targetPath>
<includes>
<include>log4j2.xml</include>
</includes>
</resource>
</resources>
</build>
Changed the classpath in the project properties->actions->Run project to include the xml file
exec.args=-classpath %classpath:/Users/petervannes/NetBeansProjects/JSONLogger_2/log4j2.xml ${packageClassName}
Any other options i can try ? It is a maven project so am not able to add jars within the project properties.
-- Update 1 --
I added the property maven.test.additionalClasspath in the pom.xml including the log4j2.xml. And added a simple JUnit test.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.test.additionalClasspath>${project.basedir}/src/test/java/log4j2.xml</maven.test.additionalClasspath>
</properties>
When executing a Maven clean and build with the -X argument the log reports
properties used {java.vendor=Oracle Corporation, sun.java.launcher=SUN_STANDARD ....., maven.test.additionalClasspath=/Users/petervannes/NetBeansProjects/JSONLogger_2/src/test/java/log4j2.xml, maven.compiler.target=1.6
Still getting the error that the log4j configuration file is not found.
Running com.reddipped.test.JSONLoggerTest
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.