Chinaunix首页 | 论坛 | 博客
  • 博客访问: 634346
  • 博文数量: 17
  • 博客积分: 248
  • 博客等级: 二等列兵
  • 技术积分: 237
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-26 12:13
个人简介

别让往昔的悲伤和对未来的恐惧,毁了你当下的幸福。

文章分类

全部博文(17)

文章存档

2013年(6)

2012年(2)

2011年(9)

我的朋友

分类: 项目管理

2011-09-13 14:23:10

13.POM(project object module)
14.user jetty-maven-plugin test web project
(1)POM配置:

   
    
     org.mortbay.jetty
     jetty-maven-plugin
     7.1.6.v20100715
     
      60
      
       /test
      

     

    

   

 

 说明:
  60
    /test
(2)用户目录 ~/.m2/settings.xml的修改
 
    org.mortbay.jetty
  
 默认情况下:
  org.apache.maven.plugins和org.codehaus.mojo这两个groupId下的插件才支持命令调用,加上一上配置就可以调用:mvn jetty:run了
  
然后运行:mvn jetty:run

 使用Cargo实现自动化部署
 两种本地部署方式:standalone 和 existing 模式,
 standalone模式的POM配置:
 
   org.codehaus.cargo
   cargo-maven2-plugin
   1.0
  
    
       tomcat6x
       D:\apache-tomcat-6.0.29
    

  

  
   
     standalone
     ${project.build.directory}/tomcat6x
    
  8081
    

  

 
 部署至远程web容器:
 
   org.codehaus.cargo
   cargo-maven2-plugin
   1.0
  
    
       tomcat6x
       remote
    

  

  
   
     runtime
    
  admin
  admin123
  
    

  

 
 
 
  
15.依赖版本的界限
指定一个依赖界限:JUnit 3.8 - JUnit 4.0

junit
junit
[3.8,4.0)
test
(, )
不包含量词
[, ]
包含量词
16.依赖归类
 有一组逻辑上归类在一起的依赖。你可以创建一个打包方式为pom项目来将这些依赖归在一起;比如hibernate和spring的依赖可以抽取一个独立的pom别的项目可以直接添加依赖关系。
 pom取名persistence-deps的项目然后建立pom文件如下:
 

 org.graux.maventest
 persistence-deps
 1.0
 pom
 
  
     org.hibernate
   hibernate
   ${hibernateVersion}
  

  
   org.hibernate
   hibernate-annotations
   ${hibernateAnnotationsVersion}
  

  
   org.springframework
   spring-hibernate3
   ${springVersion}
  

  
   mysql
   mysql-connector-java
   ${mysqlVersion}
  

 

 
  (5.1,)
  (2.0.6,)
  3.2.5.ga
  3.3.0.ga
 

 然后运行mvn install,注意packaging 为pom;然后在依赖的项目的pom里添加如下依赖:
  
   
    org.sonatype.mavenbook
    persistence-deps
    1.0
    pom
   

  

 这样省去很多重复pom配置。
  
17.生命周期深入
 (1) 清理生命周期(clean)
 包含三个生命周期阶段:
  pre-clean
  clean
  post-clean
 自定义clean的行为: 
 
  4.0.0
  ...
  
   
    
     maven-clean-plugin
     
      
       
        target-other
        
         *.class
        

       

      

     

    

   

  

 

 
 (2) maven的默认生命周期:
 validate 验证项目是否正确,以及所有为了完整构建必要的信息是否可用
 generate-sources 生成所有需要包含在编译过程中的源代码
 process-sources 处理源代码,比如过滤一些值
 generate-resources 生成所有需要包含在打包过程中的资源文件
 process-resources 复制并处理资源文件至目标目录,准备打包
 compile 编译项目的源代码
 process-classes 后处理编译生成的文件,例如对Java类进行字节码增强(bytecode enhancement)
 generate-test-sources 生成所有包含在测试编译过程中的测试源码
 process-test-sources 处理测试源码,比如过滤一些值
 generate-test-resources 生成测试需要的资源文件
 process-test-resources 复制并处理测试资源文件至测试目标目录
 test-compile 编译测试源码至测试目标目录
 test 使用合适的单元测试框架运行测试。这些测试应该不需要代码被打包或发布
 prepare-package 在真正的打包之前,执行一些准备打包必要的操作。这通常会产生一个包的展开的处理过的版本(将会在Maven 2.1+中实现)
 package 将编译好的代码打包成可分发的格式,如JAR,WAR,或者EAR
 pre-integration-test 执行一些在集成测试运行之前需要的动作。如建立集成测试需要的环境
 integration-test 如果有必要的话,处理包并发布至集成测试可以运行的环境
 post-integration-test 执行一些在集成测试运行之后需要的动作。如清理集成测试环境。
 verify 执行所有检查,验证包是有效的,符合质量规范
 install 安装包至本地仓库,以备本地的其它项目作为依赖使用
 deploy 复制最终的包至远程仓库,共享给其它开发人员和项目(通常和一次正式的发布相关)
 
 (3)站点生命周期(site)
  pre-site
  site
  post-site
  site-deploy 
 (4)打包相关生命周期
  jar默认目标:
  process-resources resources:resources
  compile compiler:compile
  process-test-resources resources:testResources
  test-compile compiler:testCompile
  test surefire:test
  package jar:jar
  install install:install
  deploy deploy:deploy
  
  pom默认目标:
  package site:attach-descriptor
  install install:install
  deploy deploy:deploy
  
18.配置额外的资源文件
 在pom中添加resource元素 
 
  ...
  
   
    src/main/resources
   

   
    src/main/xml
   

   
    src/main/images
   

  

  ...
 
19.maven默认情况下单元测试中遇到一个遇到失败就停止构建,可以设置testFailureIgnore来改变
  
 
  
   
    org.apache.maven.plugins
    maven-surefire-plugin
    
     true
    

   

  ...
  

 
20.让maven跳过test
 mvn install -Dmaven.test.skip=true(跳过测试代码的编译) 
 
 mvn package-DskipTests
 
 修改POM文件:
 
   org.apache.maven.plugins
   maven-surefire-plugin
   2.5
  
      true
  

 

21.profile
 Profile能让你为一个特殊的环境自定义一个特殊的构建;profile使得不同环境间构建的可移植性成为可能。
22.manve repository
 
 maven 仓库分为本地仓库也远程仓库,本地仓库的默认位置:windowns 下,用户目录\.m2\repository(C:\Users\guarx\.m2)
 有时候由于磁盘空间不足,可以更换repository的位置,可以修改~\.m2\settings.xml,增加如下配置:
 
  D:\java\repository
 

 
 maven的远程仓库:maven默认的远程仓库,M2_HOME/lib/maven-model-builder-3.0.jar,然后查看org/apache/maven/model/pom-4.0.0.xml如下:
 
  
   ...
   
   ...
  

 

 
 jboss Maven仓库的配置:
 
  ...
  
   
             jboss
      Jboss Repository
     
     
        true
     

        
          false
     

     
     
default

  

  ...
 
 远程仓库的认证:
 认证信息需要配置在~/.m2/setting.xml里:
 
  
   
             my-proj
      repo-user
      preo-password
   
  

 

 
 镜像:
 配置使用私服作为镜像(~/.m2/settings.xml):
 
  
    
        internal-repository
       Internal Repository Manager
      
        *
        

  
 
23. Maven 仓库搜索服务
 Sonatype Nexus
 jarvana
 MVNbrowser
 MVNrepository

24. Nexus 创建私服
 ~/.m2/settings.xml关于nexus的配置

.... 

 
  nexus-releases
  deployment
  deployment123
 

 
  nexus-snapshots
  deployment
  deployment123
 

 
 
   
      nexus
      *
     
   

 

 
 
   
      nexus
     
    
          central
         
       true
       true
       

     

    
  
    central
   
    true
    true
  

  

   

 
 
    nexus
 

...
 
25. 部署构建至nexus

   
      nexus-releases
      Nexus Releases Repository
     
   

   
      nexus-snapshots
      Nexus Snapshots Repository
     
   

   
      site.deployments
      Site deployments
      file:////opt/tomcat/webapps/sites/${project.artifactId}/
   

 
26.测试覆盖率报告
 Cobertura(测试覆盖率统计工具) 
 mvn cobertura:cobertura

27使用hudson进行持续集成(Continous Integration)
 hudson 运行:
 java -jar hudson.war --httpPort=8082
 也可以部署到servlet容器
 
 hudson Maven 项目测试报告
 配置页面的Post-build Actions --->Publist JUnit test result report
 Test report XMLs=* * /target/surefire-reports/TEST-*.xml
阅读(1361) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~