说明:
本文描述Eclipse环境下基于Maven的项目开发环境的搭建,操作系统为Windows 7 32位中文企业版。
使用的工具列表如下:
1. Oracle JDK 1.6 update 26
2. Eclipse 3.6.2 JavaEE (plugins:subclipse、m2eclipse、spring tool suite)
3. Maven 3.0.3 + Nexus
4. Apache Tomcat 6.0.32
环境准备:
1. Java环境:设置JAVA_HOME变量;设置PATH变量,增加%JAVA_HOME%\bin(建议加到最前);
2. Maven环境:设置M2_HOME变量;设置MAVEN_OPTS变量(取值如:-Xmx256m);设置PATH变量,增加%M2_HOME%\bin;
3. 配置Maven:
注:此处假定Nexus私服已搭建并配置完毕。
修改settings.xml文件:
增加mirror配置:
1 | < mirrors > |
2 | < mirror > |
3 | < id >nexus</ id > |
4 | < mirrorOf >*</ mirrorOf > |
5 | < name >A Local Nexus Server</ name > |
6 | < url >http://URL:PORT/nexus/content/groups/public</ url > |
7 | </ mirror > |
8 | </ mirrors > |
增加profile配置:
01 | < profiles > |
02 | < profile > |
03 | < id >nexus</ id > |
04 | < repositories > |
05 | < repository > |
06 | < releases >< enabled >true</ enabled ></ releases > |
07 | < snapshots >< enabled >true</ enabled ></ snapshots > |
08 | < id >nexus</ id > |
09 | < name >Repository for Local Nexus Server</ name > |
10 | < url >http://URL:PORT/nexus/content/groups/public</ url > |
11 | < layout >default</ layout > |
12 | </ repository > |
13 | </ repositories > |
14 | < pluginRepositories > |
15 | < pluginRepository > |
16 | < releases >< enabled >true</ enabled ></ releases > |
17 | < snapshots >< enabled >true</ enabled ></ snapshots > |
18 | < id >nexus</ id > |
19 | < name >Plugin Repository for Local Nexus Server</ name > |
20 | < url >http://URL:PORT/nexus/content/groups/public</ url > |
21 | </ pluginRepository > |
22 | </ pluginRepositories > |
23 | </ profile > |
24 | </ profiles > |
设置激活profile:
1 | < activeProfiles > |
2 | < activeProfile >nexus</ activeProfile > |
3 | </ activeProfiles > |
注:可以直接修改%M2_HOME%\conf目录下的settings.xml,但建议在操作系统的用户主目录下的.m2目录下添加(Maven安装后默认没有此.m2目录,在命令行键入maven相关命令后该目录将自动生成,如输入“mvn -version”)
4. 安装插件:
subclipse:
update site: http://subclipse.tigris.org/update_1.6.x
注:subclipse插件安装后默认显示中文,如想改为英文界面,可以在Eclipse安装目录的eclipse.ini文件中增加如下设置:-Duser.language=en
m2eclipse:
update site: http://m2eclipse.sonatype.org/sites/m2e
除此之外m2eclipse还有扩展插件,update site:http://m2eclipse.sonatype.org/sites/m2e-extras,需要安装其中的SCM和WTP集成的插件。
spring tool suite:
update site: dist.springsource.com/release/TOOLS/market-place/e3.6/
注:因Maven运行时需要JDK环境,建议将Eclipse运行在JDK环境中,在Eclipse安装目录的eclipse.ini文件中增加如下配置(注意换行):
-vm
YOUR_JAVA_HOME/bin/javaw.exe
项目搭建
创建Maven工程:
File->Import->Maven->Check out Maven Projects from SCM
选择SVN工程位置(如果工程包含多个Maven模块,可自行决定是否“Check out All projects”):
部署web应用(如果Maven模块中包含Web应用,m2eclipe插件能将其识别为一个web工程):
在Servers view中的Tomcat Server上右键点击,选择“Add and Remove”。然后就可以通过运行或调试方式启动Tomcat Server,应用会自动部署。
原文地址:http://my.oschina.net/moon/blog/28483