0

I try to load a configuration for log4j using the PropertyConfigurator.configure("log4j.properties") method but I keep running into java.io.FileNotFoundException.

I followed this question and placed my log4j.properties file into the resources folder.

I Also edited my pom.xml like this :

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <targetPath>${project.build.directory}</targetPath>
            <includes>
                <include>log4j.properties</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>src.Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

So when I run mvn package the target folder generated contains my .jar and my log4j.properties side by side but when I run my jar I get the file not found exception.

How can I fix this issue ?

Community
  • 1
  • 1
panic
  • 2,004
  • 2
  • 17
  • 33

1 Answers1

0

Note : Please, DO NOT include the log4j.properties into the final Jar file, it will cause multiple log4j.properties files in the classpath, if someone is depending on your Jar, you may accidentally override their logging configurations, depends which Jar is loaded first.

For reference : https://www.mkyong.com/maven/maven-exclude-log4j-properties-in-jar-file/

K_Bist
  • 91
  • 1
  • 5