"mvn clean" - Compile Maven Project

Q

How to clean up my Maven project output files? I only want to keep my Java source code.

✍: FYIcenter.com

A

When you drive your project to different phases, Maven will generate different output files in the "target" sub-directory.

Here is the project file tree of the "hello" project at the "package" phase:

C:\fyicenter\hello>tree /f  .

C:\FYICENTER\HELLO
|   pom.xml
|
|---src
|   |---main
|   |   |---java
|   |       |---com
|   |           |---fyicenter
|   |                   App.java
|   |
|   |---test
|       |---java
|           |---com
|               |---fyicenter
|                       AppTest.java
|
|---target
    |   hello-1.0-SNAPSHOT.jar
    |
    |---classes
    |   |---com
    |       |---fyicenter
    |               App.class
    |
    |---generated-sources
    |   |---annotations
    |---generated-test-sources
    |   |---test-annotations
    |---maven-archiver
    |       pom.properties
    |
    |---maven-status
    |   |---maven-compiler-plugin
    |       |---compile
    |       |   |---default-compile
    |       |           createdFiles.lst
    |       |           inputFiles.lst
    |       |
    |       |---testCompile
    |           |---default-testCompile
    |                   createdFiles.lst
    |                   inputFiles.lst
    |
    |---surefire-reports
    |       com.fyicenter.AppTest.txt
    |       TEST-com.fyicenter.AppTest.xml
    |
    |---test-classes
        |---com
            |---fyicenter
                    AppTest.class

You can run the "mvn clean" command to remove Maven output files:

C:\fyicenter\hello>\fyicenter\apache-maven-3.5.4\bin\mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------ com.fyicenter:hello >-------------------------
[INFO] Building hello 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello ---
[INFO] Deleting C:\fyicenter\hello\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.715 s
[INFO] ------------------------------------------------------------------------


C:\fyicenter\hello>tree /f  .
C:\FYICENTER\HELLO
|   pom.xml
|
|---src
    |---main
    |   |---java
    |       |---com
    |           |---fyicenter
    |                   App.java
    |
    |---test
        |---java
            |---com
                |---fyicenter
                        AppTest.java

 

"mvn dependency:copy-dependencies" - JAR Dependencies

Maven Project Build Phases

Using Apache Maven

⇑⇑ FAQ for Apache Maven

2020-10-17, 990🔥, 0💬