步骤1::首先在http://www.eclipse.org/downloads/中在官方的eclipse
下载上面的java ee版本
本版本中自带maven,但是好像不完整还需要自己手动安装。
步骤2:到http://maven.apache.org/下载maven ,有maven3.1.1以及其他的,我使用的是3.1.1.
要注意的是:下载(Binary zip) 不要下载其他的。其他的安装是有问题。
步骤3:下载完成后,解压到指定文件夹下面
然后在环境变量中将bin下的路径配置进去。注意jdk也一定要配置好而且格式如下:
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_45
CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
MACEN_OPTS=-Xms256m -Xmx512m
M2_HOME=D:\eclipse\maven\apache-maven-3.1.1
path后面加上“%M2_HOME%\bin;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin”
注意配置不同的环境变量时一定要在中间加英文分号。
步骤4:在cmd窗口中输入mvn -v或者mvn -version如果显示版本就表示配置成功。如下图:
我是成功啦!
步骤5:然后修改路径:
apache-maven-3.1.1\conf下的settings.xml可以设置jar包的存放位置,已经下载路径。操作如下:
2.修改 settings.xml
在 Maven 中使用 OSChina 的 Maven 服务还需要简单配置一下 Maven,在 Maven 的安装目录下的 conf 文件下有个 settings.xml 文件,接下来我们需要对这个文件做简单的修改,修改前您可以简单备份下该文件。 打开 settings.xml 文件,按下面内容修改。或者点击 settings.xml 下载
01 | < mirrors > |
02 | <!-- mirror | Specifies a repository mirror site to use instead of a given |
03 | repository. The repository that | this mirror serves has an ID that matches |
04 | the mirrorOf element of this mirror. IDs are used | for inheritance and direct |
05 | lookup purposes, and must be unique across the set of mirrors. | --> |
06 | < mirror > |
07 | < id >nexus-osc</ id > |
08 | < mirrorOf >*</ mirrorOf > |
09 | < name >Nexus osc</ name > |
10 | < url >http://maven.oschina.net/content/groups/public/</ url > |
11 | </ mirror > |
12 | </ mirrors > |
这里是配置 Maven 的 mirror 地址指向OSChina 的 Maven 镜像地址。 在执行 Maven 命令的时候, Maven 还需要安装一些插件包,这些插件包的下载地址也让其指向 OSChina 的 Maven 地址。修改如下内容。
01 | < profile > |
02 | < id >jdk-1.4</ id > |
03 |
04 | < activation > |
05 | < jdk >1.4</ jdk > |
06 | </ activation > |
07 |
08 | < repositories > |
09 | < repository > |
10 | < id >nexus</ id > |
11 | < name >local private nexus</ name > |
12 | < url >http://maven.oschina.net/content/groups/public/</ url > |
13 | < releases > |
14 | < enabled >true</ enabled > |
15 | </ releases > |
16 | < snapshots > |
17 | < enabled >false</ enabled > |
18 | </ snapshots > |
19 | </ repository > |
20 | </ repositories > |
21 | < pluginRepositories > |
22 | < pluginRepository > |
23 | < id >nexus</ id > |
24 | < name >local private nexus</ name > |
25 | < url >http://maven.oschina.net/content/groups/public/</ url > |
26 | < releases > |
27 | < enabled >true</ enabled > |
28 | </ releases > |
29 | < snapshots > |
30 | < enabled >false</ enabled > |
31 | </ snapshots > |
32 | </ pluginRepository > |
33 | </ pluginRepositories > |
34 | </ profile > |
如果您需要修改 Maven 的默认文件保存路径,需要在 settings.xml 文件中修改如下地方。
1 | < localRepository >F:/Maven/repo/m2/</ localRepository > |
按照如上修改 settings.xml 之后,您就可以在自己的 Maven 中使用 OSChina 为您提供的 Maven 服务了。
然后就是在eclipse中的操作
在help->eclipse marketplace中的search的find中输入maven就可以找到下载的Maven Profiles Management 1.5.0
点击install安装,然后就可以创建maven项目
在导入jar包后可能出现Missing artifact com.sun:tools:jar:1.5.0错误
那么在pom.xml中加入如下代码即可
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
添加jar包后,然后开始编写代码,