"mvn package" - Compile Maven Project

Q

How to compile a Maven project?

✍: FYIcenter.com

A

You can run the "mvn package" command to compile a Maven project:

C:\fyicenter>cd hello

C:\fyicenter\hello>\fyicenter\apache-maven-3.5.4\bin\mvn package

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------ com.fyicenter:hello >-------------------------
[INFO] Building hello 1.0
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2
   /org/apache/maven/plugins/maven-resources-plugin/3.0.2/maven-resources-plugin-3.0.2.pom
Downloading from central: https://repo.maven.apache.org/maven2
   /org/apache/maven/plugins/maven-plugins/30/maven-plugins-30.pom (10 kB at 41 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2
   /org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.jar
Downloading from central: https://repo.maven.apache.org/maven2
   /org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.jar
...
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ hello ---
Downloading from central: https://repo.maven.apache.org/maven2
   /org/codehaus/plexus/plexus-utils/2.0.4/plexus-utils-2.0.4.pom
Downloading from central: https://repo.maven.apache.org/maven2
   /org/codehaus/plexus/plexus-utils/3.0.24/plexus-utils-3.0.24.pom
Downloading from central: https://repo.maven.apache.org/maven2
   /org/codehaus/plexus/plexus/4.0/plexus-4.0.pom
...

Downloading from central: https://repo.maven.apache.org/maven2
   /org/apache/xbean/xbean-reflect/3.4/xbean-reflect-3.4.jar
Downloading from central: https://repo.maven.apache.org/maven2
   /com/google/collections/google-collections/1.0/google-collections-1.0.jar
Downloading from central: https://repo.maven.apache.org/maven2
   /junit/junit/3.8.2/junit-3.8.2.jar

[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 1 source file to C:\fyicenter\hello\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:45 min
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 
   (default-compile) on project hello: Compilation failure: Compilation failure:
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

After so many unnecessary downloads from Maven repository, the compilation process actually failed with 2 errors:

  • The default JDK version for source code is 5, which is too low.
  • The default JDK version for target class code is 1.5, which is too low.

You can modify the project file pom.xml to the above settings.

 

pom.xml - Maven Project File

"mvn archetype:generate" - Generate Maven Project

Using Apache Maven

⇑⇑ FAQ for Apache Maven

2020-10-20, 1247🔥, 0💬