`

maven环境配置以及myeclipse集成

阅读更多
一、maven环境的配置
1准备
安装jdk,本机使用的是1.6
下载maven3.0.3
2,将maven解压到指定目录,本机解压后maven的根目录是:D:\Program Files\apache-maven-3.0.3
3,配置环境变量:
新增环境变量:M2_HOME = D:\Program Files\apache-maven-3.0.3
修改环境变量:path=%path%;% M2_HOME %\bin;    即,在path后加上% M2_HOME %\bin;

4,测试maven是否安装成功
在命令行界面中输入
Echo % M2_HOME %
回车,
结果如下:

输入 mvn –v,查看maven版本

5,启动myeclipse9
6,菜单项 window—>preferences—>myeclipse—>maven4myeclipse—>maven—>installations,
点击右侧add按钮,选择本地maven的根目录,添加后,点击apply和ok按钮。
7,菜单项 window—>preferences—>myeclipse—>maven4myeclipse—>maven—>user setting
修改user settings 指定到本地maven的conf\setting.xml,点击update settings,apply 和ok。
[/size]

二、项目里的pom.xml类似于以下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0         http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>maventest</groupId>
     <artifactId>maventest</artifactId>
     <packaging>jar</packaging>
     <version>0.0.1-SNAPSHOT</version>
     <name>Maven Quick Start Archetype</name>
     <url>http://maven.apache.org</url>
     <dependencies>
       <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
  </dependencies>
</project>

向项目中添加依赖jar包:
        <dependency>
           <groupId>org.apache.struts</groupId>
           <artifactId>struts2-core</artifactId>
           <version>2.0.11</version>
       </dependency>

三、maven操作
    在cmd中找到对应项目地址,然后敲如下命令:
        1. mvn eclipse:clean  清除Project中以前的编译的东西,重新再来
        2. mvn eclipse:eclipse  开始编译Maven的Project
    在Myeclipse中的操作:

        1. 选中Maven Project 右击 在Run As中选择Maven clean
       2. 在Myeclipse中,Project—Clean  开始编译
        3. 选中Maven Project 右击 在Run As中选择Maven install

四、maven仓库及仓库配置
   1.找到maven安装路径下的conf文件夹,打开setting.xml,找到类似
   <localRepository>D:\maven_repository</localRepository>
   按如上修改仓库地址,一般刚安装的maven是在C:\Users\Administrator\.m2\repository这个路径下创建仓库。
   2.配置内网仓库和外网仓库
可能有的公司只能上内网,因此配置内网仓库非常有必要。

Maven搜索依赖的顺序就是:
1)搜索本地仓库,没有找到,就去第2步,否则退出
2)搜索内网仓库,没有找到,就去第3步,否则退出
3)搜索远程仓库获取,没有找到,就报错
<!--nexus repository install-->
<profile>
       <id>dev</id>
     <repositories>
              <repository>
                 <id>nexus</id>
                 <url>http://people.apache.org/repo/m2-incubating-repository/</url>
                 <releases>
                    <enabled>true</enabled>
                 </releases>
                 <snapshots>
                    <enabled>true</enabled>
                 </snapshots>
              </repository>
    </repositories>           
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
    <url>http://repository.sonatype.org/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                   </snapshots>
                </pluginRepository>
            </pluginRepositories>
</profile>
</profiles>
  
五、maven外网仓库地址
由于中央仓库有的时候不能访问,我们需要一定知道多个外网仓库以便下载依赖jar包
下面列出几个maven仓库地址供大家使用。
共有的仓库
http://repo1.maven.org/maven2/
http://repository.jboss.com/maven2/
http://repository.sonatype.org/content/groups/public/
http://mirrors.ibiblio.org/pub/mirrors/maven2/org/acegisecurity/

私有的仓库
http://repository.codehaus.org/
http://snapshots.repository.codehaus.org/
http://people.apache.org/repo/m2-snapshot-repository
http://people.apache.org/repo/m2-incubating-repository/
1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics