Run a Java Main Method in Maven (#9636)

This commit is contained in:
Mona Mohamadinia 2020-07-13 20:44:30 +04:30 committed by GitHub
parent db13e0ec44
commit fc6dc42152
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,5 @@
## Maven WAR Plugin
This module contains articles about the Maven Exec Plugin.
### Relevant Articles

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.baeldung</groupId>
<artifactId>maven-exec-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>maven-exec-plugin</name>
<properties>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<java.version>1.8</java.version>
<logback-classic.version>1.2.3</logback-classic.version>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-classic.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>com.baeldung.main.Exec</mainClass>
<arguments>
<argument>First</argument>
<argument>Second</argument>
<argument>Third</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,18 @@
package com.baeldung.main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
public class Exec {
private static final Logger LOGGER = LoggerFactory.getLogger(Exec.class);
public static void main(String[] args) {
LOGGER.info("Running the main method");
if (args.length > 0) {
LOGGER.info("List of arguments: {}", Arrays.toString(args));
}
}
}

View File

@ -16,6 +16,7 @@
<modules>
<!-- <module>compiler-plugin-java-9</module> --> <!-- We haven't upgraded to java 9. -->
<module>maven-custom-plugin</module>
<module>maven-exec-plugin</module>
<module>maven-integration-test</module>
<module>maven-multi-source</module>
<module>maven-plugins</module>