Wednesday, March 11, 2020

Step by Step Guide to Setup Apache Maven

1. Download Apache Maven


URL: https://maven.apache.org/download.cgi
or
https://maven.apache.org/ click Download link


  • Downloaded Maven version -> apache-maven-3.6.1 (This is as per my wish, you can always download the latest)
  • Placed the folder -> C:\apache-maven-3.6.1

2. Set Environment Variable and Path in Windows Machine


Control Panel -> All Control Panel Items -> System 
Advanced System Settings -> Environment Variables 
System Variables -> Path -> Edit -> C:\apache-maven-3.6.1\bin

3. Check Maven version using Command Prompt


Command:
mvn --version

Example:

C:\Users\Manokaran\Documents\projects\first-maven-project>mvn --version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T00:30:29+05:30)
Maven home: C:\apache-maven-3.6.1\bin\..
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: C:\java8.201\JDK\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

4. Create Maven Project Folder:


Open folder i.e, C:\Users\YOUR_NAME\Documents\


  • C:\Users\Manokaran\Documents\
  • Create new folder i.e, first-maven-projectwork


5. Generate Maven Archetype


Open folder i.e, C:\Users\Manokaran\Documents\first-maven-projectwork using Command Prompt

Command:

mvn archetype:generate

C:\Users\Manokaran\Documents\first-maven-projectwork>mvn archetype:generate
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.1.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
.......
.......
.......

.......
2582: remote -> uk.co.solong:angular-spring-archetype (So Long archetype for RESTful spring services with an AngularJS frontend. Includes debian deployment)
2583: remote -> us.fatehi:schemacrawler-archetype-maven-project (-)
2584: remote -> us.fatehi:schemacrawler-archetype-plugin-command (-)
2585: remote -> us.fatehi:schemacrawler-archetype-plugin-dbconnector (-)
2586: remote -> us.fatehi:schemacrawler-archetype-plugin-lint (-)
2587: remote -> ws.osiris:osiris-archetype (Maven Archetype for Osiris)
2588: remote -> xyz.luan.generator:xyz-gae-generator (-)
2589: remote -> xyz.luan.generator:xyz-generator (-)
2590: remote -> za.co.absa.hyperdrive:component-archetype (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1497: PRESS ENTER

then type the Number as 8 in below Standard Input..

Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
7: 1.3
8: 1.4

Choose a number: 8: 8

6. Fillup Information about your Maven Project:



Define value for property 'groupId': com.sampleproject
Define value for property 'artifactId': trial-maven-project
Define value for property 'version' 1.0-SNAPSHOT: : 1.0-SNAPSHOT
Define value for property 'package' com.sampleproject: : com.sampleproject.demo

Confirm properties configuration:
groupId: com.sampleproject
artifactId: trial-maven-project
version: 1.0-SNAPSHOT
package: com.sampleproject.demo
 Y: : Y


[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.sampleproject
[INFO] Parameter: artifactId, Value: trial-maven-project
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.sampleproject.demo
[INFO] Parameter: packageInPathFormat, Value: com/sampleproject/demo
[INFO] Parameter: package, Value: com.sampleproject.demo
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: com.sampleproject
[INFO] Parameter: artifactId, Value: trial-maven-project
[INFO] Project created from Archetype in dir: C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  09:43 min
[INFO] Finished at: 2020-03-11T18:04:10+05:30
[INFO] ------------------------------------------------------------------------


7. Check latest changes in your Maven Project Folder


Open folder i.e, C:\Users\Manokaran\Documents\first-maven-projectwork

you can see a new folder i.e, trial-maven-project (this we gave as 'artifactId')

once you open the folder path -> C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project.  You can notice pom.xml (Project Object Model XML file) and src folder.

8. Compile Maven Project


C:\Users\Manokaran\Documents\first-maven-projectwork>cd trial-maven-project

C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.sampleproject:trial-maven-project >----------------
[INFO] Building trial-maven-project 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ trial-maven-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ trial-maven-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.113 s
[INFO] Finished at: 2020-03-11T18:13:59+05:30
[INFO] ------------------------------------------------------------------------

C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project>

9. TEST Maven Project


C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.sampleproject:trial-maven-project >----------------
[INFO] Building trial-maven-project 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ trial-maven-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ trial-maven-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ trial-maven-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ trial-maven-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\Manokaran\Documents\first-maven-projectwork\trial-maven-project\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ trial-maven-project ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.sampleproject.demo.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.032 s - in com.sampleproject.demo.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.663 s
[INFO] Finished at: 2020-03-11T18:16:10+05:30

No comments:

Post a Comment

Popular Posts