Eclipse使用Maven构建web项目

1.创建Maven项目:
点击“File”菜单,或者通过工具栏的“New”创建Project,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6360/7bbd3283-228a-3cef-bdf2-e613c3a0dfb4.png[/img]

选择Maven-》Maven Project,弹出向导对话框,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6362/b3f7bb83-23bd-3679-860c-26ee3333f597.png[/img]

选中Create a simple project……复选框,其它的设置不变,并点击Next,输入maven项目必须的信息(groupId,artifactid,version),如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6364/223e4c15-ed19-330e-a153-c78103d6400c.png[/img]

这里需要选择Packaging,web项目一般选择war即可。点击Finish,完成项目创建,下图为创建的项目结构(项目名称为:sample-webapp):

[img]http://dl.iteye.com/upload/attachment/0082/6366/279913f1-a8bf-3cd8-ab6d-c57ce1e8278f.png[/img]

2.配置web项目:
右键点击sample-webapp项目,依次点击Properties-》Project Facets-》Convert to faceted form… ,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6370/c1eff860-433f-30a0-b3c9-304566726083.png[/img]

勾选Dynamic Web Module,并选择版本(这里使用2.5,由于3.0版本需要tomcat7),如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6368/783d0ddb-0706-3f88-a558-9812470bf067.png[/img]

点击OK,此时,项目结构树增加了WebContent文件夹,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6374/ed0a2eb8-be04-3438-b9c9-6c8f01217fb7.png[/img]

将WebContent下的WEB-INF、META-INF文件夹copy到src/main/webapp目录下,并且删除WebContent目录,完成之后,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6376/e3d8339d-8f11-3973-b16d-04c9c1e31195.png[/img]

右键点击sample-webapp项目,依次点击Properties-》Deployment Assembly,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6378/9161ad36-092e-397b-a0fd-0e8a81aa47fa.png[/img]

此时,通过Remove按钮删除/src/test/java、/src/test/resources、/WebContent,并且通过Add添加webapp与maven依赖,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6380/cb18380c-3b8f-3539-b913-a790d8b24148.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6380/cb18380c-3b8f-3539-b913-a790d8b24148.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6384/b7db043b-3252-3e0c-b8a1-058f60cbc9a5.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6386/48d1cb06-07ba-34ed-9692-b5386b72f5e6.png[/img]

首先Add-》Folder,选择webapp目录并Finish,再选择Java Build Path Entries-》Maven Dependencies
完成之后,如下图所示:

[img]http://dl.iteye.com/upload/attachment/0082/6388/2e1a56b7-1636-3c24-857f-50c3e79bba96.png[/img]

3.部署web项目:
添加tomcat server,并部署web项目,这里不描述,与非maven项目基本相同。

[img]http://dl.iteye.com/upload/attachment/0082/6392/67cc9c5b-5232-356c-b90b-4f4691828fe0.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6394/beed45b6-c210-3c32-ac6f-e4da461c8fa0.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6396/7993a1f6-bb9e-3a39-a78f-20521e87d1ac.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6398/21bd47b5-c244-32c1-a711-c3371a087528.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6400/f184bff3-8a6d-3ad4-b5e3-2aaef80effc2.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6402/ff174c50-f357-3bd9-b04c-1a66f6379185.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6404/f06a65ef-2d26-34d3-8e17-46e630ada787.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6406/132cf4fe-4446-320c-9c56-33fc11baf289.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6408/bf9483fb-1577-3d1e-bd47-5106033551c6.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6410/182fdb76-8f33-357a-a08c-fccec50d4140.png[/img]

[img]http://dl.iteye.com/upload/attachment/0082/6412/cb4f3088-e174-356d-a072-946d59a4fbb9.png[/img]

你可能感兴趣的:(J2EE)