How to Create a Maven Web Application.

Maven Web Application

Lets Start to create Maven Web Application.

Step 1: Open Eclipse.

Step 2: Go to File Menu --> New---> Maven Project.




Step 3: Default Workspace is already selected if you want to save project in workspace location.
If you want to save it at another location Browse your Computer to that location. and  Click Next

Step 4: Select All Catalog, Archetype as maven-archetype-webapp 1.0


Step 5: Allow it to download above archetype by clicking next.

Step 6: Now in New Maven project Dialog Box Enter Group Id and Artifact Id.

Group ID: It will identify your project uniquely across all projects, so we need to enforce a naming schema. 
It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. 
eg. org.myedu, com.shopping

ArtifactId: is the name of the jar without version.
If you created it then you can choose whatever name you want with lowercase letters and no strange symbols.
If it's a third party jar you have to take the name of the jar as it's distributed.
eg. myshoppingsite, my-education

Version: if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...).
Don't use dates as they are usually associated with SNAPSHOT (nightly) builds.
If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look.
eg. 2.0, 2.0.1, 1.3.1


Step 7:  Click on Finish. Maven Web App will be Created . Allow Maven to download templates before starting. Close the Welcome Tab.

** By Default Compiler of Project is of Version 1.5. Change it to Version you need. Here I am Changing it to Version 1.8

Step 8: Right Click your Project  Go to Buid Path---> Configure Build Path.


Step 9:  Go to Java Build Path --->Libraries-->JRE System Library[J2SE-1.5] , Click on Edit and Select Workspace Default JRE (jre1.8.0). Click on Finish.




Step 10: Go to Java Compiler ---> Select Compiler Compliance Level to 1.8. Click Apply.
If ask to Build Project Click Yes.


Step 11: Click on Project Facet and change Java Version to 1.8 . Click Apply and then Ok.


Your Maven Web App Project is ready to use. 

WAIT  ... There is an Error on index.jsp Page.


you will need to add jar file of javax.servlet file to java build path. But we are using maven project so we wont manually do it. We will add dependency of jar file in pom.xml file. and maven will automatically download it for you 😊

Step 12: Add following Dependency in pom.xml file inside dependencies tag:


Step 13: Save and See Error will disappear. Run Project on Server..

What is a POM?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. 
It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/test/java; and so on.
Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on.
 Other information such as the project version, description, developers, mailing lists and such can also be specified.

** Please Comment If you Face any Problem while Creating Maven Project :)





No comments: