You can find more details in https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
1. Creating a Java Project with Maven
mvn archetype:generate
-DgroupId={project-package-name}
-DartifactId={project-name}
-DarchetypeArtifactId={maven-template-name}
-DinteractiveMode=false
-DarchetypeVersion=1.4
for example
mvn archetype:generate
-DgroupId=com.extuni.enum_demo4
-DartifactId=enum_demo4
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
-DarchetypeVersion=1.4
![](https://kenanhancer.com/wp-content/uploads/2021/01/Screenshot-2021-01-31-at-20.52.41-1024x407.png)
Maven Directory Layout
![](https://kenanhancer.com/wp-content/uploads/2021/01/Screenshot-2021-01-31-at-21.02.16.png)
Generated App.java file content
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-04-at-05.53.40.png)
POM file
Generated pom.xml file looks like as below.
![](https://kenanhancer.com/wp-content/uploads/2021/01/Screenshot-2021-01-31-at-23.04.27-1-933x1024.png)
You can see updated version of pom.xml file in the following screenshot.
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-00.56.04-924x1024.png)
2. Compiling Java Project with Maven
mvn compile
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.10.54-1024x312.png)
Directory layout will be changed as below.
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.02.51-1024x766.png)
3. Cleaning Java Project with Maven
mvn clean
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.08.37-1024x323.png)
Cleaning command deletes generated target folder as shown in the following screenshot.
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.12.23.png)
4. Compiling and running Unit tests
mvn test
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.21.57-1024x626.png)
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.36.13-914x1024.png)
Compiling Unit Test without running
If you simply want to compile your test sources (but not execute the tests), you can execute the following:
mvn test-compile
5. Packaging Java Project with Maven
It compiles, run unit test and package the project into a jar
file and puts it into the project/target
folder.
mvn package
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.30.57-1024x646.png)
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-01.37.35-911x1024.png)
Skipping Unit Test
mvn -Dmaven.test.skip=true package
6. Installing Package in Local Maven Repository
Now you'll want to install the artifact you've generated (the JAR file) in your local repository (${user.home}/.m2/repository
is the default location).
mvn install
7. Run Java main Method with Maven
Without arguments
mvn clean compile exec:java -Dexec.mainClass="com.extuni.enum_demo4.App"
With arguments
mvn clean compile exec:java -Dexec.mainClass="com.extuni.enum_demo4.App" -Dexec.args="arg0 arg1 arg2"
Updating pom.xml file
If you don't want to specify main class full path in terminal, just update pom.xml file as the following
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-01-at-03.30.11-920x1024.png)
<properties>
<exec.mainClass>com.extuni.enum_demo4.App</exec.mainClass>
</properties>
mvn clean compile exec:java
![](https://kenanhancer.com/wp-content/uploads/2021/02/Screenshot-2021-02-04-at-07.11.15-1024x484.png)
As you can see, project is cleaned, compiled and run main method. So output is Hello World! in terminal window.