0

Our project is a Spring Boot project, we are also using Apache Camel, we are using Log4j for logging and we are deploying the application as war file in JBoss EAP 7.3.0. The pom.xml of the application is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>myapplication</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <env.camel.version>2.25.1</env.camel.version>
        <spring.boot-version>2.3.3.RELEASE</spring.boot-version>
    </properties>

    <!-- Spring-Boot and Camel BOM -->
    <dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot-version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-spring-boot-dependencies</artifactId>
                <version>${env.camel.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- Camel -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-swagger-java-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-servlet-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-naming-client</artifactId>
            <version>1.0.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-jms-client</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.json</groupId>
            <artifactId>javax.json-api</artifactId>
        </dependency>
        
        <!-- MQ Client -->
        <dependency>
            <groupId>com.ibm.mq</groupId>
            <artifactId>com.ibm.mq.allclient</artifactId>
            <version>9.2.0.1</version>
        </dependency>
    </dependencies>

    <!-- Build Configurations -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot-version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>default-war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                        <configuration>
                            <attachClasses>true</attachClasses>
                            <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                            <webResources>
                                <resource>
                                    <directory>src/main/webapp</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </webResources>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <attachClasses>true</attachClasses>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

With this the following jar files gets added in the project classpath:

  1. log4j-to-slf4j-2.13.3.jar
  2. log4j-api-2.13.3.jar
  3. jul-to-slf4j-1.7.30.jar

The problem is I have another version of log4j jar file present in JBoss module and for that logs are not getting generated from my jar file because of conflicting versions of jar files. Can you please suggest me what needs to be done in pom.xml to use the log4j jar that is present in JBoss module and not the one added as maven dependency?

Anirban
  • 925
  • 4
  • 24
  • 54
  • Do you have a log4j configuration file in your deployment or do you want the logging subsystem to configure a log manager? – James R. Perkins Jun 11 '21 at 18:10
  • I have log4j.properties file in my classpath. Whwn I am deleting the file the logs are generated in my server log. Itherwise logs are not getting generated in the path I am specifying in log4j.properties file. I have tries by deleting the log4j which is present in modules.xml of JBoss and then again the logs are generating correctly. – Anirban Jun 12 '21 at 09:08
  • Are you excluding the logging subsystem or the logging API's in a `jboss-deployment-structure.xml`. – James R. Perkins Jun 13 '21 at 02:09
  • No, I am not excluding the logging subsystem. The JBoss module contains many jar files besides the log4j jar and some of the jar files will be required. For this reason I will not be able to exclude the full module from my war file. Can I only exclude one jar file (the log4j jar) using jboss-deployment-structure.xml? – Anirban Jun 13 '21 at 17:08
  • Yes you can exclude only the modules you'd like to exclude. However, if you want to use your own log configuration I'd recommend excluding the logging subsystem and provide the libraries you require. The logging dependencies provided by WildFly are designed to work with the JBoss Log Manager and the logging subsystem. – James R. Perkins Jun 13 '21 at 20:49
  • Can you please say me how to exclude the JBoss logging subsystem, will try that. – Anirban Jun 14 '21 at 04:44
  • I want to exclude any log4j jar present in my project and use the one present in JBoss module. – Anirban Jun 14 '21 at 05:29
  • I'm a little confused now. If you want to exclude the log4j libraries in your deployment and use what WildFly provides then you'd want to edit your pom. – James R. Perkins Jun 14 '21 at 15:11
  • Yes, I have tried to exclude the logging subsystem from spring-boot-starter-web dependency, but still I am able to see log4j and slf4j-to-log4j jar files in my classpath in the maven dependency. Can you please say me how cam I edit my pom so as to use the log4j jar files present inside JBoss and not those within the war file? – Anirban Jun 14 '21 at 18:58
  • You just need to mark them as `provided`. – James R. Perkins Jun 14 '21 at 22:52
  • I had tried giving scope provided on slf4j-log4j12 dependency but it did not work. Can you please guide me on which dependency I will have to mention the scope as provided? – Anirban Jun 15 '21 at 04:33
  • What is your ultimate goal? Do you want the server to configure logging or do you want to use a custom log4j configuration file? – James R. Perkins Jun 15 '21 at 15:54
  • My ultimate goal is to generate the logs in a specific location from my application. For generating the logs I am open to use any of the methods but none seems to be working because I have log4j jar files both as maven dependency and in JBoss module. – Anirban Jun 15 '21 at 17:01

0 Answers0