Home  >  Article  >  Java  >  Briefly describe how to use Eclipse to create a simple Maven JavaWeb project

Briefly describe how to use Eclipse to create a simple Maven JavaWeb project

巴扎黑
巴扎黑Original
2017-06-23 16:36:302222browse

Use Maven to create a simple javaWeb project:

This article is the third article on creating a JavaWeb project: It is recommended to read "Create a simple web project with Eclipse" before reading this article; This article is based on this article.

Steps:

1: Select in the new wizard: Maven Project

Click Next and choose not to use the skeleton first.

Supplement the company ID and project ID and select the packaging method: war

Click on the completed project framework:

## First look at the project properties: Right-click on the properties: select web deployment Assmbly First check the project deployment path:

At this time, I found that an error was reported: click in to see what error was reported:

##web.xml is missing and is set to true: means: web.xml is missing; but failOnMissingWebXml is set to true;

There are two solutions to this error: one is to fill in the missing web.xml; one It is to set to false

A web project must be indispensable for web.xml, so our solution is to fill in the missing web.xml.

How to fill it back? Just put it back. It’s OK to convert the current project into a dynamic web project;

Right-click on the properties and select the project facet: The purpose of this step is to convert the project into a dynamic web project: Replace the lost web.xml ;

1; The first step is to select the JDK version and javaScrpit version: click Apply and OK

2: Click the properties project facet again and select Dynamic Web Module: If the tomcat version is 7.0, choose 3.0; for tomcat 8/8+, choose 3.1; tomcat 6/6-, choose 3.0-;

There is a further configuration below: Ask whether to create an automatically generated web.xml The best choice here is otherwise you have to create it manually;

##After clicking OK, take a look at the project structure:

1: There is one more piece: webContent

2: No error is reported; Is there a web.xml file under the webContent directory;

3: If your webContent directory does not appear; it must be above Steps; first select the JDK and Javascript versions and then select the dynamic web module version;

Because the dynamic web module depends on the JDK version;

At this time, take a look at the project deployment path:

Right-click properties: web dployment Assembly:

Did you find that the project deployment path has changed? The previous webapp Is the path gone? Guess what this means?

1: webapp and webContent have the same function. It’s OK to keep only one; generally keep webapp (I personally think the reason is this) The directory structure looks more pleasing to the eye)

So the next step is to 1: Modify the project structure directory (only one of webapp and webContent is retained, usually webapp); 2: Modify the web deployment assembly in Deployment path;

Copy the content under the webContent directory to the webapp; and delete the webContent directory;

## Configure web deployment path:

Delete the test and webContent directories first;

Then add: select the webapp directory

Take a look at the completed Directory structure: If pom.xml reports an error; cut and paste the pom.xml inside and it will be OK;

The structure directory of the project is now set up;

Next modify the pom.xml file: Post my pom.xml file here;

<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 ">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.etoak</groupId>
  <artifactId>mjw01</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- javaEE -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
        </dependency>

        <!-- servlet start -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- servlet end -->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
        <finalName>mjw01</finalName>  <!--  这里是 项目名 -->
    </build>
</project>

Next, create a new index.jsp page under the webapp (note that it cannot be built under the WEB-IBF directory, because the files under this directory cannot be directly accessed through the path in the address bar;)

The last thing left is testing; try entering the project path in the browser address bar: http://http://localhost:8080/mjw01/

Is it OK?

The above is the detailed content of Briefly describe how to use Eclipse to create a simple Maven JavaWeb project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn