1、new->other->Maven Project,点击next
2、继续next
3、选择maven-archetype-webapp,如果找不到可以再Filter里面搜索web,就可以找到了。继续next
4、输入自己定义的名称,如下:
5、之后再项目名称上面右击->Build Path->add Library->选择Server Runtime,next
6、选中Apach Tomcat v7.0(你的版本可能是6或者8),Finish
7、要建立maven结构,需要修改在项目里手动添加文件夹:
srcmainjava
srcmain esources
src estjava
src est esources
8、修改项目下面的classpath,类似下面配置:
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
eclipse生成的classpath中:
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
9、在项目名称上右击->reFresh,就可以了
10、将tomcat端口改为80。
11、将项目部署到tomcat上,运行tomcat,浏览器输入“localhost/项目名”,就可以访问了