Maven Tutorial - Maven Package Project








Since we have created an empty project we can go the C:\mvn_test\xmlFileEditor directory and execute the following mvn command to compile and package the project.

c:\mvn_test\xmlFileEditor>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xmlFileEditor 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
...
...
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to c:\mvn_test\xmlFileEditor\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ xmlFileEditor ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory c:\mvn_test\xmlFileEditor\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ xmlFileEditor ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to c:\mvn_test\xmlFileEditor\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ xmlFileEditor ---
[INFO] Surefire report directory: c:\mvn_test\xmlFileEditor\target\surefire-reports

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

Results :

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

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ xmlFileEditor ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.354 s
[INFO] Finished at: 2014-11-03T16:14:01-08:00
[INFO] Final Memory: 25M/369M
[INFO] ------------------------------------------------------------------------
c:\mvn_test\xmlFileEditor>





Note

We've built our project and created final jar file.

null

From the command above we can see that two goals can be combine into one command.

First we can clean the target directory with clean goal and then package the project build output as jar with package goal.

Packaged jar is available in xmlFileEditor\target folder as xmlFileEditor-1.0-SNAPSHOT.jar.

Test reports are available in xmlFileEditor\target\surefire-reports folder.

Maven compiled source code files and then test source code files. Then Maven run the test cases. Finally Maven created the package.