Create a Maven Web Project

In this tutorial, we will learn about creating a simple Maven web project using Eclipse and Command line.

Using Eclipse:

Technologies used –

a. Eclipse IDE for Java EE developer 4.5.0.20150621-1200 (Mars)
b. Preinstalled Maven with Eclipse Mars
c. Java 1.8

Steps:

1. Go to File > New > Maven Project

CreateMavenProject-1

2. Click on Next

3. Choose the artifact as shown below:

CreateMavenProject-2

4. Fill out the details of group id and artifact id. Values in the snapshot are just samples. You can fill out values of your choice.

CreateMavenProject-4

5. Click on Finish.

A maven based web project is ready now.

CreateMavenProject-5


Using command line in Mac:

Technologies used –
a.  Apache maven 3.3.3
b. Java 1.8

Steps:

  1. Download maven from Maven 3.3.3
  2. Unzip the folder in your favorite directory.
  3. In your Home directory, open the file .bash_profile.
  4. Make the following entry :
export M2_HOME=~/Development/apache-maven-3.3.3
export PATH=$PATH:$M2_HOME/bin
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

Note: Please note that ~(tilde) used is my home directory since I downloaded maven in my home directory. Also, version of java used may be different for you and so is your java installation directory. Please make changes accordingly.

    5.  Open command line and type the below command.

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes  -DarchetypeArtifactId=maven-archetype-webapp  -DarchetypeVersion=1.0 -DgroupId=com.javanbeyond -DartifactId=QuickCrashCourse  -Dversion=1.0-SNAPSHOT -DinteractiveMode=false

Please make sure your current directory should be the directory where you want your project to be created.

6. Press Enter and wait for the process to complete.

7. A folder with the name of your artifact Id should get created. Folder structure inside QuickCrashCourse folder.

./pom.xml
./src
./src/main
./src/main/resources
./src/main/webapp
./src/main/webapp/index.jsp
./src/main/webapp/WEB-INF
./src/main/webapp/WEB-INF/web.xml

Leave a Reply

Back to Top
%d bloggers like this: