0

I have tried this already: Mixing log4j 1.x and log4j 2 with third party libraries dependending on log4j 1.x

I am getting a log4j 1 appender error when I deploy my jar file to a docker image but do not see that when I run the main method in Eclipse.

log4j:WARN No appenders could be found for logger (blah). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Here are my dependencies

    <dependencies>
    <!-- QUARTZ Required -->
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.3.2</version>
    </dependency>

    <!-- Kafka -->
    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka_2.12</artifactId>
        <version>2.3.1</version>
    </dependency>

    <!-- SSO Web Form -->
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.11.3</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit</artifactId>
        <version>2.34.1</version>
    </dependency>

    <!-- JSON -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.10.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.10.0</version>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
        <version>2.4.0</version>
    </dependency>

    <!-- CSV -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.7</version>
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.29</version>
    </dependency>

    <!-- SQL -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc</artifactId>
        <version>${ojdbc.version}</version>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.8.9</version>
        <scope>test</scope>
    </dependency>
</dependencies>

I have tried removing everything that I can (including log4j-1.2-api) that may have reference to log4j 1 to compile and test (outside of removing the references to slf4j in my code and using the log4j api) to no avail.

My command to start my jar file is:

java -Dlog4j.configurationFile=$LOGGING_CFG -Ddatacollector.config.dir=$CONFIG_DIR -jar blah.jar

I verified my parameters are valid and have made sure the config works in the IDE. I even tried programatically loading the file using Configurator.initialize(name, filePath). I suspect that log4j 1 is somehow in my environment and I want to scrub it out.

Thanks for your help.

shinds
  • 756
  • 7
  • 13
  • Can you share your project's maven dependency tree? You need the log4j-1.2-api jar but remove any _log4j:log4j:_ transitive dependencies. – Ramu Nov 13 '19 at 14:00

1 Answers1

0

I resolved the problem by updating the maven assembly plugin version to 3.1.1.

       <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <!-- Needed to get the correct log4j -->
            <version>3.1.1</version>
            <executions>
                <execution>
                    <id>distrib</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId><!--$NO-MVN-MAN-VER$ -->
                        <outputDirectory>docker/jar/</outputDirectory>
                        <archive>
                            <manifest>
                                <mainClass>my.main.class</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <finalName>my-app-${project.version}</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
shinds
  • 756
  • 7
  • 13