Maven - Maven Web Application - maven tutorial
What is Web Application?
- Web application is a client-server software application in which the client (or user interface) runs in a web browser.Common web applications include webmail, online retail sales, online auctions, wikis, instant messaging services and many other functions.
- We can create a simple maven web application example by executing the archetype: generate command of mvn tool.
- To create a simple java project using maven, you need to open command prompt and run the archetype: generate command of mvn tool.
learn maven tutorial - maven project - web application deployment - Apache Maven example programs
maven tutorial tags : apache maven , maven repository , maven central
Syntax
- The syntax to generate the project architecture is given below:
Example
- The example to generate the project architecture is given below:
- mvn archetype:generate -DgroupId=com.wikitechy -DartifactId=CubeGeneratorWeb
- -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
- Note: Here, we are using maven-archetype-webapp to create simple maven web application. if you use maven-archetype-quick start, it will generate a simple maven core project.
- Now it will generate following code in the command prompt:
Output
Generated Directory Structure
- Now go to the current directory from where you have executed the mvn command.
- For example: d:\CubeGeneratorWeb. You will see that a simple java project is created that has the following directory:
- As you can see, there are created 3 files pom.xml, index.jsp and web.xml. Let's have a quick look at these files:
1.Automatically Generated pom.xml file
maven tutorial tags : apache maven , maven repository , maven central
2.Automatically Generated index.jsp file
3.Automatically Generated web.xml file
Deploy and Run the Maven Web Project
- Now you need to deploy the project on the server and access it by the following url:
- http://<host-name>:<portnumber>/projectname,:
- http://localhost:8888/CubeGeneratorWeb
maven tutorial tags : apache maven , maven repository , maven central
Example:
Maven Webapp in Eclipse
You can import the maven web project in eclipse. To do so, perform following steps:
- Open eclipse IDE
- Import the maven project
- File Menu -> Import -> Maven -> Existing Maven Projects
- Next -> Browse Project
- Finish.
Run the maven web project
- Right click on project -> Run As -> Run on Server