maven2的平常使用

1. 安装

http://maven.apache.org/download.html 中下载最新版本

解压缩, 并且正确设置环境变量

具体操作如官方说明一样:

Windows 2000/XP
  1. Unzip apache-maven-2.0.8-bin.zip to the directory you wish to install Maven 2.0.8. These instructions assume you chose C:\Program Files\Apache Software Foundation\apache-maven-2.0.8
  2. Add the bin directory to your path, by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then editing the PATH variable in the user variables. eg. "C:\Program Files\Apache Software Foundation\apache-maven-2.0.8\bin";%PATH%
  3. In the same dialog, make sure that JAVA_HOME is set to the location of your JDK, eg. C:\Program Files\Java\jdk1.5.0_02
  4. Run mvn --version to verify that it is correctly installed.
Unix-based Operating Systems (Linux, Solaris and Mac OS X)
  1. Extract the distribution archive to the directory you wish to install Maven 2.0.8. These instructions assume you chose /usr/local/apache-maven-2.0.8 . The directory apache-maven-2.0.8 will be created from the archive.
  2. Add the bin directory to your path, eg. export PATH=/usr/local/apache-maven-2.0.8/bin:$PATH
  3. Make sure that JAVA_HOME is set to the location of your JDK, eg. export JAVA_HOME=/usr/java/jdk1.5.0_02
  4. Run mvn --version to verify that it is correctly installed.  

2.生成Maven项目

生成标准布局的webapp项目,在控制台执行下面命令(groupId后面是包名,artifactId后面是项目名称):

mvn archetype:create -DgroupId=net.jeffrey
         -DartifactId=my-webapp
         -DarchetypeArtifactId=maven-archetype-webapp

生成标准布局的普通java项目,执行:

mvn archetype:create -DgroupId=net.jeffrey -DartifactId=my-app

完成后你会看到已经生成了一个名为my-webapp的文件夹,这就是刚刚生成好的项目目录

在my-webapp根目录下,你会看到名为pom.xml的文件,这个就是maven的项目描述文件

 

3.maven和eclipse整合

安装maven2插件 http://m2eclipse.codehaus.org/

网站中有详细的FLASH DEMO介绍安装和基本使用

4.架设artifactory私服管理

直接下载解压就可以使用

项目的pom.xml文件修改

   < repositories >
        
< repository >
            
< id > artifactory </ id >
            
< name > your local artifactory </ name >
            
< url > http://localhost:8081/artifactory/repo </ url >
        
</ repository >
    
</ repositories >

    
< pluginRepositories >
        
< pluginRepository >
            
< id > artifactory </ id >
            
< name > your local artifactory </ name >
            
< url > http://localhost:8081/artifactory/plugins-releases </ url >
            
< snapshots >
                
< enabled > false </ enabled >
            
</ snapshots >
        
</ pluginRepository >
    
</ pluginRepositories >

具体的依赖写法,要参考 http://mvnrepository.com/

修改artifactory的下载地址为:  <remoteRepository>
            <key>repo1</key>
            <handleReleases>true</handleReleases>
            <handleSnapshots>false</handleSnapshots>
            <excludesPattern>org/artifactory/**,org/jfrog/**</excludesPattern>
           <!-- <url>http://repo1.maven.org/maven2</url>-->
     <url>http://mirrors.redv.com/maven2</url>
        </remoteRepository>
在/etc/artifactory.config.xml中!

 

 

5.与myeclipse的结合

0. 为eclipse添加Maven2和MyEclipse插件

1. 将Maven项目转为Eclipse项目,具体操作为将dos命令窗口切换到Maven项目的目录下,输入命令: mvn eclipse:eclipse

2. 进入eclipse,将这个项目导入工作空间

3. 在该项目上点右键Maven->Enable

4. 在该项目上点右键Build Path->Configure Build Path->Java Build Path->Libraries->去掉Maven添加的变量路径

5. 在该项目上点右键MyEclipse->Add Web Capabilities->修改Web root地址(点【浏览】按钮指定为当前工作空间下的src/main/webapp文件夹)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值