`

Maven使用

    博客分类:
  • Java
阅读更多

一、maven常用命令

1、mvn clean compile:编译命令;

执行上述命令成功build 后,Maven会在工程目录下新建target目录,该目录将包含所有通过编译的字节码文件。

 

2、mvn clean:清理命令;

执行上述命令将会清除工程目录下的target目录。

 

3、mvn test:测试命令;

执行上述命令则会执行src/test/java 目录下的所有Junit 测试代码,当然执行此命令之前会先执行编译命令。

此命令执行顺序为:mvn clean compile --> mvn test

 

4、mvn package:打包命令;

执行上述命令会将项目打成jar包,并放在target目录中,当然执行此命令之前会先执行编译和测试命令。

此命令执行顺序为:mvn clean compile --> mvn test --> mvn package

 

5、mvn install:安装命令;

执行上述命令则会将项目的jar包安装到本地仓库中,以便其他项目调用,当然执行此命令之前会先执行编译,测试,打包等命令。

此命令执行顺序为:mvn clean compile --> mvn test --> mvn package --> mvn install
 

二、maven配置

(1)、本机maven配置

     a、配置环境变量

             M2_HOME

              path

     b、设置本地仓库地址

               在%M2_HOME%/conf/settings.xml中配置                    

  1. <localRepository>e:/program/repository</localRepository>

     c、设置HTTP代理(可选)

               %MAVEN_HOME%/conf/settings.xml                             

  1. <proxy>
     <id>optional</id>
     <active>true</active>
     <protocol>http</protocol>
     <username>proxyuser</username>
     <password>proxypass</password>
     <host>192.168.101.194</host>
     <port>8888</port>
     <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
     
       d、设置私服 
  1. <servers>
    <server>
    <id>nexus-repo</id>
    <username>admin</username>
    <password>admin123</password>
    </server>
    </servers>
    <profiles>
    <profile>
    <id>nexus-repo</id>
    <repositories>
    <repository>
    <id>nexus-repo</id>
    <name>nexus central repository</name>
    <url>http://192.168.31.3:8081/nexus/content/repositories/central/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>false</enabled>
    </snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>nexus-repo</id>
    <name>nexus central repository</name>
    <url>http://192.168.31.3:8081/nexus/content/repositories/central/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>false</enabled>
    </snapshots>
    </pluginRepository>
    </pluginRepositories>
    </profile>
    </profiles>
    <activeProfiles>
    <activeProfile>nexus-repo</activeProfile>
    </activeProfiles>
     

 (二)、maven私服搭建(具体参考附件)

    1、目的

                    解决内网开发,无法连接至maven的中央仓库的情形;

                    节省带宽;

                    规范项目所需的构件;

                    降低maven中央仓库的负载;

    2、nexus下载地址

           http://www.sonatype.org/nexus/go

    3、nexus仓库类型

                    group  仓库组      仓库集合,一对多
                    hosted  宿主        自定义仓库
                    proxy    代理        首先从私服查找,找不到从中央仓库寻找
                    virtual    虚拟
          nexus prository
                    Public Repositories:           仓库组
                    3rd party:                       无法从公共仓库获得的第三方发布版本的构件仓库
                    Apache Snapshots:          用了代理Apache Maven仓库快照版本的构建仓库
                    Central:                          用来代理maven中央仓库中发布版本构件的仓库
                    Central M1 shadow:           提供中央仓库中M1格式的发布版本的构建的镜像仓库
                    Codehaus Snapshots:        
                    Releases:                        用来部署管理内部的发布版本构件的宿主类型仓库
                    Snapshots:                      用来部署管理内部的快照版本构件的宿主类型仓库
   4、启动nexus
                     bin\jsw\windows-x86-32
                              console-nexus.bat        启动nexus
                              install-nexus.bat           将nexus安装为windows服务
                              start-nexus.bat              启动nexus服务         
                              stop-nexus.bat               停止nexus服务
                              uninstall-nexus.bat          卸载nexus服务
  5、访问nexus
                    浏览器访问:http://localhost:8081/nexus         
                    默认用户名/密码: admin/admin123

 

 三、使用eclipse构建maven的springMVC项目(具体见附件)

 

四、eclipse中利用jetty进行maven项目的调试(具体见附件)

     

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics