Categories
java maven

Create a Maven Project using command prompt

In this tutorial we will learn to create a maven project using command prompt 

Prerequisites
Syntax
mvn archetype:generate -DgroupId= -DartifactId= -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Sample
mvn archetype:generate -DgroupId=com.beginnergsbug -DartifactId=sample-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Output

C:\Users\USHA RAJESH\Desktop\sample>mvn archetype:generate -DgroupId=com.beginnergsbug -DartifactId=sample-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
[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.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.pom (703 B at 1.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom (1.5 kB at 3.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom (1.3 kB at 2.9 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar (4.3 kB at 7.6 kB/s)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\USHA RAJESH\Desktop\sample
[INFO] Parameter: package, Value: com.beginnergsbug
[INFO] Parameter: groupId, Value: com.beginnergsbug
[INFO] Parameter: artifactId, Value: sample-project
[INFO] Parameter: packageName, Value: com.beginnergsbug
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\USHA RAJESH\Desktop\sample\sample-project
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  12.855 s
[INFO] Finished at: 2020-01-31T09:17:42+05:30
[INFO] ------------------------------------------------------------------------

C:\Users\USHA RAJESH\Desktop\sample>     
Syntax Explanation

mvn maven base command

archetype:generate= to generate a maven project

-DgroupId= group id for the project

-DartifactId= artifact id it is similar to project name

-DarchetypeArtifactId= type of archetype

-DinteractiveMode= true/false 

Related Articles

How to install Apache Maven in windows

Categories
java maven

Set Maven Home in Windows

In this tutorial we will learn to set Maven home in windows.

Please refer my previous tutorial to download and install maven.

This is the follow up tutorial of my previous post

Prerequisites

Step 1

Copy Maven installed Path

In my case it is C:\Maven\apache-maven-3.6.3

Apache Maven Home

Step 2

Open My computer 

Step 3

Right click the This PC

Step 4

Click on Properties

Step 5

Click on Advanced system settings

Step 6

Click on the Environment variables

Step 7

Click New on the System variables column

Step 8

Enter Variable name as M2_HOME
Enter Variable value as C:\Maven\apache-maven-3.6.3
click ok
Note :
Variable name should be CAPS
Variable value should be as your maven installed path
don’t copy until bin folder

M2_HOME

Step 9

After Click OK
we can see the M2_HOME variable in environment variables

Step 10

After Click OK
we can see the M2_HOME variable in environment variables

Step 11

Now we need to need to add this JAVA_HOME to Path variable
Search for Path variable in same system variables window

Step 12

After selecting Path variable
Click on Edit button

Step 13

Edit environment variable dialog box will appear
Click on the New button

Step 14

Text box will appear on the list
add %M2_HOME%\bin in the text box

Step 15

Click OK after adding %M2_HOME%\bin
Now close all the windows

Step 16

We can verify by below steps
open the command prompt
type mvn -version

mvn -version

That’s it !! 

Related Articles

Create a Maven Project using command prompt

Categories
java maven

How to install Apache Maven in windows

In this tutorial we will learn about install apache maven in windows operating system

Maven is a software project management tool like gradle
maintaining by Apache 

If you are new to maven then below points will help you to understand maven

  • It is one of the easiest way to create a Java project
  • Easy to manage the dependencies (external jars)
  • Easy to build a jar or war
  • The project size will be so less

pom.xml

pom stands for Project Object Model
pom.xml is the heart of a maven project
It is a xml file which will have all dependency and build details for that project 

Prerequisites

Step 1

Download apache maven binary zip version from below URL 
http://apachemirror.wuchna.com/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip

Step 2

After downloading zip file.

Extract and place in some folder

In this example I am creating Maven folder on C: Directory of my windows Operating system

The folder path is like C:\Maven\apache-maven-3.6.3

Apache Maven Home

That’s it !! 

We installed Apache maven in windows. Please follow next tutorial to setup maven home 

We can use mvn command only if we have JAVA_HOME and M2_HOME in environment variables

Refer this tutorial to set M2_HOME 
https://beginnersbug.com/set-maven-home-in-windows/

if not we will face below exceptions

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
'mvn' is not recognized as an internal or external command,
operable program or batch file.
Related Articles

Set Maven Home in Windows

Create a Maven Project using command prompt