Eclipse integrated Maven Web project demo (independent and Maven integrated tomcat)

 

Tools used
JDK1.8
Eclipse Luna j2ee
Eclipse integrated Maven
tomcat7 (independent web server integrated in xampp, or integrated web server through Maven plugin)

The steps are as follows:
1. Create a new Maven web project,

A

B

 

 

 

C

D

 Then you will get the following project tree

You can see that there is a red warning, this is because the java web server is missing, you can install tomcat, then add the server in eclipse and deploy the web program.

You can also integrate tomcat through the Maven plugin, and use maven to publish web programs to automatically deploy web programs.

2. Configure tomcat

After installing xampp, tomcat7 is integrated, but do not start tomcat separately at this time, it will be started in eclipse later.

The configuration steps are as follows, create a new server in the runtime of the project properties, the type is tomcat7

 

Fill in the tomcat installation directory and find it in xampp,

Make sure the project has been added to the server, if not, you need to add it manually (right click on the server, add and remove)

After adding the server, there is no warning in the project directory, and the web project can be run at this time.

 

 Right-click on index.jsp and select run->run on server

 

3. Use Maven's tomcat plugin to deploy web programs.

The independent tmcat deployment method was used earlier. Since we are creating a maven project, integrating various third-party tools (such as web servers) through maven can give full play to the advantages of maven.

We add the following two paragraphs to the pom file to integrate the tomcat server and automatically publish the function.

The first is the jsp dependency library,

copy code

 1     <dependencies>
 2         <dependency>
 3             <groupId>junit</groupId>
 4             <artifactId>junit</artifactId>
 5             <version>3.8.1</version>
 6             <scope>test</scope>
 7         </dependency>
 8         <dependency>
 9             <groupId>javax.servlet</groupId>
10             <artifactId>servlet-api</artifactId>
11             <version>2.5</version>
12             <scope>provided</scope>
13         </dependency>
14         <dependency>
15             <groupId>javax.servlet.jsp</groupId>
16             <artifactId>jsp-api</artifactId>
17             <version>2.2</version>
18             <scope>provided</scope>
19         </dependency>
20         <dependency>
21             <groupId>javax.servlet</groupId>
22             <artifactId>jstl</artifactId>
23             <version>1.2</version>
24         </dependency>
25         <dependency>
26             <groupId>jsptags</groupId>
27             <artifactId>pager-taglib</artifactId>
28             <version>2.0</version>
29             <scope>provided</scope>
30         </dependency>
31     </dependencies>

copy code

Then configure maven's tomcat plugin, put it in <build>,

copy code

 1   <build> 
 2     <finalName>maven-web-demo</finalName>  
 3     <plugins> 
 4       <plugin> 
 5         <groupId>org.apache.tomcat.maven</groupId>  
 6         <artifactId>tomcat7-maven-plugin</artifactId>  
 7         <version>2.2</version>  
 8         <configuration> 
 9           <port>8080</port>  
10           <path>/maven-web-demo</path>  
11           <uriEncoding>UTF-8</uriEncoding>  
12           <finalName>maven-web-demo</finalName>  
13           <server>tomcat7</server> 
14         </configuration>  
15         <executions> 
16           <!-->--Start running the web container after the package is successful  
17           <execution> 
18             <phase>package</phase>  
19             <goals> 
20               <goal>run</goal> 
21             </goals> 
22           </execution> 
23         </executions> 
24       </plugin> 
25     </plugins> 
26   </build>

copy code

Configure maven run again

In run configuation, configure Maven run

 

 

 The key point above is to fill in tomcat:run in Goals, and then click the Run button directly below, you can see the console results,

Seeing that the 8080 description has been published successfully, enter http://localhost:8080/maven-web-demo/ in the browser

It should be noted that it is best to specify the java version number in maven. I used java8 at first, but there is no version specified in maven (it is estimated that the default is java7),

It was always compiled, but it was incomprehensible. Finally, it was changed to java7 to run, and then I suddenly realized. Eclipse, maven, and native java need to be unified.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325780682&siteId=291194637