Getting Started with Maven | Creating a Maven Project | Creating a Program (mvn package)

Now compile the project and create the program. There are several ways to do this, but the easiest is to use the package creation command.

In a command prompt or terminal, run cd SampleMavenApp to move into the SampleMavenApp folder. Then run the following command.

mvn package

When execution completes, Maven compiles the program and creates a Jar file. This package is called a Maven “goal.” For now, understand it simply as the way to create a package with mvn package.

When the command runs, a very long message is printed. If the end of the output looks like the following, the Jar file was created successfully.

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ SampleMavenApp ---
[INFO] Building jar: /Users/kimkc/dev/mvn/SampleMavenApp/target/SampleMavenApp-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.122 s
[INFO] Finished at: 2017-12-11T23:57:15+09:00
[INFO] Final Memory: 15M/141M
[INFO] ------------------------------------------------------------------------

Just before that output, you should also see output like this.

 T E S T S
-------------------------------------------------------
Running com.devkuma.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

This is the result of running unit tests. When a Maven project is created, it generates not only a sample source code file but also a unit test source file for testing that source code. During the build, Maven runs the prepared unit tests, and if there are no problems, it creates the package.