Apache Commons Logging + Log4J 2 + Maven Assembly Plugin + Maven Exec Plugin!

just another one!

Directory Layout

pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0">
 
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>biz.tugay</groupId>
    <artifactId>mvnlogex</artifactId>
 
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
 
    <name>mvnlogex</name>
    <url>http://www.tugay.biz</url>
 
    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
 
        <!-- Scope: runtime -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.8.1</version>
            <scope>runtime</scope>
        </dependency>        
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.8.1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>2.0</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>biz.tugay.mvnlogex.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>biz.tugay.mvnlogex.App</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

log4j.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration status="WARN">
    <appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %p %c [%t] %m%n"/>
        </Console>
        <File name="LogFile" fileName="/Users/koraytugay/Desktop/mvnlogex.log">
            <PatternLayout>
                <Pattern>%d %p %c [%t] %m%n</Pattern>
            </PatternLayout>
        </File>
    </appenders>
    <loggers>
        <root level="INFO">
            <appender-ref ref="Console"/>
            <appender-ref ref="LogFile"/>
        </root>
    </loggers>
</configuration>

MANIFEST.MF
Main-Class: biz.tugay.mvnlogex.App
 

App.java
package biz.tugay.mvnlogex;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
public class App {
 
    private final static Log logger = LogFactory.getLog(App.class);
 
    public static void main(String[] args) {
        logger.info("hey is your info!");
        System.out.println(logger.getClass());
    }
}

Build..
Korays-MacBook-Pro:mvnlogex koraytugay$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building mvnlogex 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mvnlogex ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvnlogex ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mvnlogex ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/koraytugay/Desktop/mvnlogex/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mvnlogex ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/koraytugay/Desktop/mvnlogex/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mvnlogex ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mvnlogex ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mvnlogex ---
[INFO] Building jar: /Users/koraytugay/Desktop/mvnlogex/target/mvnlogex-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) @ mvnlogex ---
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] org/ already added, skipping
[INFO] org/apache/ already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] org/ already added, skipping
[INFO] org/apache/ already added, skipping
[INFO] org/apache/logging/ already added, skipping
[INFO] org/apache/logging/log4j/ already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/maven/org.apache.logging.log4j/ already added, skipping
[INFO] META-INF/DEPENDENCIES already added, skipping
[INFO] META-INF/LICENSE already added, skipping
[INFO] META-INF/NOTICE already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/services/ already added, skipping
[INFO] org/ already added, skipping
[INFO] org/apache/ already added, skipping
[INFO] org/apache/logging/ already added, skipping
[INFO] org/apache/logging/log4j/ already added, skipping
[INFO] META-INF/DEPENDENCIES already added, skipping
[INFO] META-INF/LICENSE already added, skipping
[INFO] META-INF/NOTICE already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/maven/org.apache.logging.log4j/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] Building jar: /Users/koraytugay/Desktop/mvnlogex/target/mvnlogex-1.0-SNAPSHOT-jar-with-dependencies.jar
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] org/ already added, skipping
[INFO] org/apache/ already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] org/ already added, skipping
[INFO] org/apache/ already added, skipping
[INFO] org/apache/logging/ already added, skipping
[INFO] org/apache/logging/log4j/ already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/maven/org.apache.logging.log4j/ already added, skipping
[INFO] META-INF/DEPENDENCIES already added, skipping
[INFO] META-INF/LICENSE already added, skipping
[INFO] META-INF/NOTICE already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/services/ already added, skipping
[INFO] org/ already added, skipping
[INFO] org/apache/ already added, skipping
[INFO] org/apache/logging/ already added, skipping
[INFO] org/apache/logging/log4j/ already added, skipping
[INFO] META-INF/DEPENDENCIES already added, skipping
[INFO] META-INF/LICENSE already added, skipping
[INFO] META-INF/NOTICE already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/maven/org.apache.logging.log4j/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mvnlogex ---
[INFO] Installing /Users/koraytugay/Desktop/mvnlogex/target/mvnlogex-1.0-SNAPSHOT.jar to /Users/koraytugay/.m2/repository/biz/tugay/mvnlogex/1.0-SNAPSHOT/mvnlogex-1.0-SNAPSHOT.jar
[INFO] Installing /Users/koraytugay/Desktop/mvnlogex/pom.xml to /Users/koraytugay/.m2/repository/biz/tugay/mvnlogex/1.0-SNAPSHOT/mvnlogex-1.0-SNAPSHOT.pom
[INFO] Installing /Users/koraytugay/Desktop/mvnlogex/target/mvnlogex-1.0-SNAPSHOT-jar-with-dependencies.jar to /Users/koraytugay/.m2/repository/biz/tugay/mvnlogex/1.0-SNAPSHOT/mvnlogex-1.0-SNAPSHOT-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.634 s
[INFO] Finished at: 2017-03-30T11:38:29+03:00
[INFO] Final Memory: 22M/439M
[INFO] ------------------------------------------------------------------------

Running with exec:java
Korays-MacBook-Pro:mvnlogex koraytugay$ mvn exec:java
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building mvnlogex 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) > validate @ mvnlogex >>>
[INFO] 
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) < validate @ mvnlogex <<<
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ mvnlogex ---
2017-03-30 11:39:24,039 INFO biz.tugay.mvnlogex.App [biz.tugay.mvnlogex.App.main()] hey is your info!
class org.apache.logging.log4j.jcl.Log4jLog
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.091 s
[INFO] Finished at: 2017-03-30T11:39:24+03:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------

Running with java -jar
Korays-MacBook-Pro:target koraytugay$ java -jar mvnlogex-1.0-SNAPSHOT-jar-with-dependencies.jar 
2017-03-30 11:39:51,094 INFO biz.tugay.mvnlogex.App [main] hey is your info!
class org.apache.logging.log4j.jcl.Log4jLog