安装Maven
下载安装
去maven官网下载最新版。
解压到安装目录。
配置
右键桌面的计算机图标,属性–>高级系统设置–>环境变量,添加M2_HOME
的环境变量,然后将该变量加入的PATH
中。
注意 必须要有JAVA_HOME
和个环境变量,不然maven会提示错误。
id="iframe_0.1744248759932816" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131211943.png?attname=&e=1422797138&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:1XRvEZM3617eMd_qoIaP145q49w&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.1744248759932816',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 558px;">
id="iframe_0.9781034393236041" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131212150.png?attname=&e=1422797138&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:5C7pUPCV7UvFNUrfhHFG51o767c&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9781034393236041',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 494px; height: 602px;">
id="iframe_0.9814521216321737" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131212514.png?attname=&e=1422797138&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:IW7_L2PDsUM8jUjWJR-X-dR-Jcs&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9814521216321737',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 450px; height: 546px;">
如果想要修改maven的本地仓库位置,可以在maven的安装目录下的conf目录下的settings.xml配置文件中设置。
id="iframe_0.7280689210165292" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131213204.png?attname=&e=1422797574&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:BZjzLjo1jyvFjIQPpxxJjg90TKE&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7280689210165292',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 380px;">
打开CMD,输入mvn --version
,看到如下提示就说明安装成功了。
id="iframe_0.15325422724708915" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131213547.png?attname=&e=1422797760&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:7nSMl85KYVzWVplBibSOZNE2XUQ&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.15325422724708915',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 661px; height: 407px;">
配置IntelliJ
在IntelliJ的设置中,可以设置maven的安装目录,settings.xml文件的位置,和本地仓库的位置等信息。
id="iframe_0.18995716446079314" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131214059.png?attname=&e=1422798079&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:xoAahXVnOfT6WQ7g0M8HTZzI3vQ&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.18995716446079314',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 683px;">
新建
新建maven项目,create from archetype,选择maven-archetype-webapp
id="iframe_0.9608364345040172" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/2015013101.png?attname=&e=1422795839&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:4DHDuqSA-aqqVZL2ToP-7ZpJwu4&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9608364345040172',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 748px; height: 602px;">
Next,填写GroupId,ArtifactId和Version
id="iframe_0.829566894331947" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131210639.png?attname=&e=1422796020&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:ogUmxYsQQgdf3rA68uZWI7IYuv4&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.829566894331947',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 749px; height: 599px;">
Next,这里在Properties中添加一个参数archetypeCatalog=internal
,不加这个参数,在maven生成骨架的时候将会非常慢,有时候会直接卡住。
来自网上的解释:
archetypeCatalog表示插件使用的archetype元数据,不加这个参数时默认为remote,local,即中央仓库archetype元数据,由于中央仓库的archetype太多了,所以导致很慢,指定internal来表示仅使用内部元数据。
id="iframe_0.21898427652195096" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131214447.png?attname=&e=1422798312&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:bfAVtk3dLctPaOCV5gxFNwcoz1E&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.21898427652195096',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 743px; height: 589px;">
Next,填写项目名称和module名称。
id="iframe_0.41747325332835317" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131214955.png?attname=&e=1422798607&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:FL2LEbE_LkhsgNN3F9XkWF6T7qs&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.41747325332835317',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 744px; height: 588px;">
点击Finish。
项目的目录结构如下:
id="iframe_0.9579875655472279" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131215310.png?attname=&e=1422798808&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:tb1Ra30K8DAc56O0_C5WxXY8MGg&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9579875655472279',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 335px; height: 353px;">
设置
配置项目的JDK和language level
id="iframe_0.44547992548905313" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131215606.png?attname=&e=1422801407&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:Qq36p9NA2tjxI1EgYb5Vn2GSq-Q&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.44547992548905313',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 864px; height: 685px;">
在main文件夹下新建一个java文件夹,把它设为源代码文件夹。
id="iframe_0.9990984932519495" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131215824.png?attname=&e=1422801407&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:w3y6uQiZlUmZRmJAmfI9E54ktjg&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9990984932519495',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 869px; height: 682px;">
为module添加外部依赖的jar包。
id="iframe_0.6155952936969697" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131220444.png?attname=&e=1422801407&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:Y0vo1r2iVHOd6wEH2zb7idJo37M&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6155952936969697',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 683px;">
添加tomcat的依赖是为了满足servlet
和jsp
依赖的,tomcat作为一个servlet
容器提高了servlet
和jsp
的API。
id="iframe_0.2783123159315437" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131225335.png?attname=&e=1422802468&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:o9Vd6jSUyu3XdALnNJ5C92u2C_A&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.2783123159315437',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 425px;">
id="iframe_0.009479970205575228" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131225348.png?attname=&e=1422802468&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:A71Y_CJ-3xN1sh31_m_4praGRQM&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.009479970205575228',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 538px; height: 497px;">
添加jar包依赖。
id="iframe_0.9235950142610818" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131220505.png?attname=&e=1422801407&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:hvi356PNA72drN5DAKrQ6uUYU6E&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9235950142610818',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 671px;">
设置artifact。
id="iframe_0.22183791804127395" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131220648.png?attname=&e=1422801407&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:679478Vri3aAhyUn8wauXfBns9A&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.22183791804127395',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 868px; height: 677px;">
设置tomcat。
id="iframe_0.890021116938442" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131220725.png?attname=&e=1422801407&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:8X5Dop_0BMo6iAkoH4N1jWVBbkk&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.890021116938442',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 507px;">
id="iframe_0.02513267775066197" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131220857.png?attname=&e=1422801676&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:T3tgvP0D0YNXHWC18ueFYn2ZE4M&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.02513267775066197',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 506px;">
id="iframe_0.36086340923793614" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131224727.png?attname=&e=1422802062&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:8UDLUcy9j2tu0p7IPkQp3FI6tb0&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.36086340923793614',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 870px; height: 497px;">
启动tomca
id="iframe_0.2244190506171435" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131225000.png?attname=&e=1422802234&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:7tR7fbImqm7z7JQlAyxu-D8BGRE&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.2244190506171435',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 421px; height: 66px;">
访问
id="iframe_0.22980223409831524" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://7u2r8z.com1.z0.glb.clouddn.com/20150131225016.png?attname=&e=1422802234&token=bm0aGge7R2WSvVmK5LOvS5P0w6J5-Dt0_YCJMk1I:EgKZHwiVQO0THOlBC7_9F839iCs&_=4658765%22%20style=%22border:none;max-width:870px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.22980223409831524',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-style: none; border-width: initial; width: 351px; height: 119px;">
完!