用ideal创建一个maven的javaweb

顺序是:
file----->new----->project----->点击左边的maven
----->点击上方的Create from archetype
----->然后选择右边的maven-archetype-webapp骨架
填写样例:
Groupld: com.lz.other
Artifactld: javawebDemo
Version:默认
**********************************************************************************
**********************************************************************************
----->然后点击两次next
----->接着在main里面建立一个java包,
然后右击java包点击显示的使之变为Sources Root
(如果在main里面建立一个resources文件同样点击这个,但是是点Resources Root)
**********************************************************************************
**********************************************************************************
----->然后在java中建立servlet文件时会报错,
因为pom文件中没有servlet-api和jsp-api,所以要去导入如下:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
**********************************************************************************
**********************************************************************************
----->最后还要在web.xml中配置你所建立的servlet文件如下:
<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>com.lz.servlet.testServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
**********************************************************************************
**********************************************************************************
----->接着还要在pom文件中导入tomcat7和jsp如下:
(注意这里有模板,只需要打出tomcat7或jsp回车即可)
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8888</port>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.8</target>
<source>1.8</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
**********************************************************************************
**********************************************************************************
----->最后是项目运行点击最右边的;
----->然后点击m的图标:输入tomcat7:rum就可以运行项目了
 

 转载于:http://zhenyunboy.icu/?p=148

posted @ 2020-10-16 10:07  振云博客  阅读(110)  评论(0编辑  收藏  举报