How to create a Web project with maven under Intelj

Source: Internet
Author: User

I believe that the first students to do Web projects are directly put the project package in the Web-inf/lib directory, and then began to do the project. But then we were exposed to a few projects that used MAVEN for package management, and we had to learn how to do package management with MAVEN.

Read a lot of articles on the Internet, found are not very comprehensive, so the process of their own groping down, I hope to help you. This article focuses on how to move from a non-package-managed project development model to a project package management using MAVEN.

Do the programming, for the new knowledge, first run up, but not to delve into its principles. Here we use MAVEN to build a simple Web project that allows it to run. This allows us to have a perceptual understanding of maven.

Before you start you need the following (any version can be):

    • IntelliJ Idea 12.1.4
    • JDK 1.6.0_51
    • Maven 3.0.4
    • Tomcat 6

1. Create a MAVEN project

If it is the first time to open the software directly click on Create New Project, if you have previously opened the project, you need to click on the menu File→new project ... Such as:

Click Next to enter GroupId, Artifactid:

Click Next to enter the project name as follows:

Click Finish to complete.

2. Create the project source directory and set it to source folder (4)

MAVEN requires that you create the following source Folder:

Src/main/resources

Src/main/java

Src/test/resources

Src/test/java

Some Ides will automatically create the above folder for you after you create the project (project), and if not, we'll need to create it manually.

After you create it, you need to set it as the source folder for the project, and click on the project right-clicking on "Open Module Setting" to open the following attempt:

After completion, the folder structure and status are as follows:

3, modify the output directory (4)

Right-click on the project name to open the "open Module Setting" view:

The output path defines the source file's code file and the export directory of the resource file.

Test output path defines the code file for the testing source file and the output directory of the test resource file.

The output directories corresponding to the 4 source folders correspond to:

Src/main/resources corresponding to Chanshuyi_demo (project name)/target/classes

Src/main/java corresponding to Chanshuyi_demo (project name)/target/classes

Src/test/resources corresponding to Chanshuyi_demo (project name)/target/test-classes

Src/test/java corresponding to Chanshuyi_demo (project name)/target/test-classes

In general, this is set by default, and we do not need to set it manually. If you do not have Setup, you need to set it manually.

4. Set class library (dependent)

Or, right-click on the project name to open the "open Module Setting" view and navigate to the Dependencies option:

If you see an error in the dependency above, then re-import the dependency. In general, the default settings are correct.

5, increase the facets of the Web project

In fact, this step is to set the Src/main/webapp directory as the content directory of the Web project, which is similar to the meaning of setting the source folder.

Open the "Open Module Setting" menu, click on the "Facets" menu and click on the + sign.

In the pop-up window select the Chanshuyi_demo module, modify the 3 positions indicated by the arrow to be the correct path:

6. Create Artifacts

Creating a artifacts is actually a matter of packaging the project and deploying it for later Tomcat calls. Select the "Artifacts" menu in "Open Module Setting" as shown in:

Select Chanshuyi_demo in the pop-up window and save it immediately after the popup menu is not modified.

7. Deploy the project to Tomat

Click "Run", "Edit configurations" to open the configuration and create a local tomcat server as shown:

Then, in the Server tab, configure the following properties such as Tomcat's directory, Tomcat Port, and so on:

Then click the Deployment tab, add the arfifacts you want to deploy, and select Chanshuyi_demo:

The creation and deployment of a project here has been completed.

Then start Tomcat and test to see if the deployment was successful. Click Start Item,

After the start of the first page will automatically open, if you see the following screen that is successful deployment.

But because each person's situation is different, you may encounter other errors. If you encounter a: Errot listenstart error, then the configuration of the Web. xml file is wrong, you can replace the following code in Web. XML:

 <?  xml version= "1.0" encoding= "UTF-8"  ?>  <  web-app  version  = "2.5"   xmlns  = "Http://java.sun.com/xml/ns/javaee"   Xmlns:xsi  = "Http://www.w3.org/2001/XMLSchema-instance"   Xsi:schemalocation  = "http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_ 5.xsd " >  </ web-app  >  

It should be possible to succeed. If not, then follow the prompts to modify.

How to create a Web project with maven under Intelj

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.