maven中创建web项目

1.创建普通的maven项目


2.项目结如下,pom提示错误


pom中的内容为


提示:Cannot detect Web Project version. Please specify version of Web Project through Maven project 

 property <webVersion>. E.g.: <properties> <webVersion>3.0</webVersion> </properties>错误

发生这个错误的原因是缺少 maven-war 插件,在pom中添加相应的插件

3.添加 maven-war插件。如下,然后右键maven --- >update project

      <plugin>  
          <artifactId>maven-war-plugin</artifactId>  
          <version>2.4</version>  
          <configuration>  
              <version>3.0</version>  
          </configuration>  
      </plugin>




4.上步的pom错误消失了,提示如下错误


这是缺少 web.xml,需要手动添加web.xml

5.在src\main\webapp下创建WEB-INF,在WEB-INF下创建web.xml


web.xml的内容为

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

把上面内容复制到 web.xml中  放入到项目中即可


这样项目就变成了web工程项目

6.在webapp里放入index.html后,把index.html配置放入到web.xml中的<welcom-file>中,启动服务就可以访问了。






猜你喜欢

转载自blog.csdn.net/fefsdf/article/details/79698257