Maven tutorial Article 03: creating a web application

Source: Internet
Author: User

1. Use the following command to create a web application:

Code

 MVN archetype: generate  -  Dgroupid  =  Net. Jianxi. tutorials. MAVEN
- Dartifactid = Webappdemo
- Dpackage = Net. Jianxi. tutorials. MAVEN
- Darchetypeartifactid = Maven - Archetype - Webapp
- Dversion = 1.0 - Dinteractivemode = No

The created web applicationProgramThe directory structure is as follows:

2. Run the following command to create a web packaging file:

MVN package

You can see the following directory structure:

3. Configure Pom. XML to run the web application directly.

This is the webappdemo generated in the previous step. war is directly published to the Web application server, such as Tomcat. to access your application. in Maven, you can directly configure POM to test your web application. XML supports jetty. the following is the Pom. XML:

 <  Project Xmlns  = "Http://maven.apache.org/POM/4.0.0"  Xmlns: xsi  = "Http://www.w3.org/2001/XMLSchema-instance"  Xsi: schemalocation  = "Http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"  >  
< Modelversion > 4.0.0 </ Modelversion >
< Groupid > Net. Jianxi. tutorials. MAVEN </ Groupid >
< Artifactid > Webappdemo </ Artifactid >
< Packaging > War </ Packaging >
< Version > 1.0 </ Version >
< Name > Webappdemo Maven webapp </ Name >
< URL > Http://maven.apache.org </ URL >

< Dependencies >
< Dependency >
< Groupid > JUnit </ Groupid >
< Artifactid > JUnit </ Artifactid >
< Version > 4.7 </ Version >
< Scope > Test </ Scope >
</ Dependency >
</ Dependencies >

< Build >
< Finalname > Webappdemo </ Finalname >
< Plugins >
< Plugin >
< Groupid > Org. mortbay. Jetty </ Groupid >
< Artifactid > Maven-jetty-plugin </ Artifactid >
</ Plugin >
</ Plugins >
</ Build >
</ Project >

In this way, you can run the following command to start your web application:

 
> MVN jetty: Run

Then you can access the Web application through: http: // localhost: 8080/webappdemo.

1. Use the following command to create a web application:

Code

 MVN archetype: generate  -  Dgroupid  =  Net. Jianxi. tutorials. MAVEN
- Dartifactid = Webappdemo
- Dpackage = Net. Jianxi. tutorials. MAVEN
- Darchetypeartifactid = Maven - Archetype - Webapp
- Dversion = 1.0 - Dinteractivemode = No

The directory structure of the created web application is as follows:

2. Run the following command to create a web packaging file:

MVN package

You can see the following directory structure:

3. Configure Pom. XML to run the web application directly.

This is the webappdemo generated in the previous step. war is directly published to the Web application server, such as Tomcat. to access your application. in Maven, you can directly configure POM to test your web application. XML supports jetty. the following is the Pom. XML:

 <  Project  Xmlns = "Http://maven.apache.org/POM/4.0.0"  Xmlns: xsi  = "Http://www.w3.org/2001/XMLSchema-instance"  Xsi: schemalocation  = "Http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"  >  
< Modelversion > 4.0.0 </ Modelversion >
< Groupid > Net. Jianxi. tutorials. MAVEN </ Groupid >
< Artifactid > Webappdemo </ Artifactid >
< Packaging > War </ Packaging >
< Version > 1.0 </ Version >
< Name > Webappdemo Maven webapp </ Name >
< URL > Http://maven.apache.org </ URL >

< Dependencies >
< Dependency >
< Groupid > JUnit </ Groupid >
< Artifactid > JUnit </ Artifactid >
< Version > 4.7 </ Version >
< Scope > Test </ Scope >
</ Dependency >
</ Dependencies >

< Build >
< Finalname > Webappdemo </ Finalname >
< Plugins >
< Plugin >
< Groupid > Org. mortbay. Jetty </ Groupid >
< Artifactid > Maven-jetty-plugin </ Artifactid >
</ Plugin >
</ Plugins >
</ Build >
</ Project >

In this way, you can run the following command to start your web application:

 
> MVN jetty: Run

Then you can access the Web application through: http: // localhost: 8080/webappdemo.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.