maven 杂七杂八

path :整体copy C:\ProgramData\Oracle\Java\javapath;E:\jdk1.8.0_20\bin;C:\Program Files\TortoiseSVN\bin;%MAVEN_HOME%\bin;


%MAVEN_HOME%\bin;


JAVA_HOME

寻找jar包的pom 地址:http://mvnrepository.com/


java 安装完毕


maven 安装完毕


创建项目
  模块划分  log
            service
            control
            dao
            comment

            parent

搭建私服:

1.下载  nexus oss
  
2.配置环境变量 bin

3.修改 G:\soft\nexus-oss-1.8.0-bundle\nexus-2.11.1-01\bin\jsw\conf  wrapper.conf
4.启动:G:\soft\nexus-oss-1.8.0-bundle\nexus-2.11.1-01\bin\jsw\windows-x86-64 (windows 64位系统)


5.工厂的作用:
   mvn:deploy  提交开发完 给工厂
   host:开发模块完毕 提交到host中
           3rd party  第三方工具
           Relasese   发布版本
           snapshot   快照
   proxy:代理工厂  从中央仓库下载下来的东西都到 central 
   group 多个工厂 放到一个中

   使用方法: repositories  设置工厂

<!-- 设置工厂 -->
<repositories>
<repository>
<id>nexus</id>
<name>NEXUS REPOSITORES</name>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
</repository>
</repositories>

<!--整体修改-->
setting.xml

  <profile>
<!--设置工厂 为本地工厂 -->
      <id>nexuspro</id>
      <repositories>
       <repository>
<id>nexus</id>
<name>NEXUS REPOSITORES</name>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
  <enabled>true</enabled>
</releases>
<snapshots>
  <enabled>true</enabled>
</snapshots>
</repository>
      </repositories>
    </profile>
   <activeProfiles>
    <!--激活nexuspro id相同 -->
    <activeProfile>nexuspro</activeProfile>
  </activeProfiles>

<profile>
<!--设置工厂 为本地工厂 -->
      <id>centerProfile</id>
      <repositories>
       <repository>
<id>center</id>
<name>NEXUS REPOSITORES</name>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
  <enabled>true</enabled>
</releases>
<snapshots>
  <enabled>true</enabled>
</snapshots>
</repository>
      </repositories>
    </profile>
   <activeProfiles>
    <!--激活nexuspro id相同 -->
    <activeProfile>centerProfile</activeProfile>
  </activeProfiles>


注意 当本地私服nexus 关闭后 会去 中央工厂获取jar http://repo.maven.apache.org/maven2/
如果想设置:只有私服开启才能下载 那么需要设置镜像 mirrors 

<!--安装镜像--> 确保服务关闭后,不在去中央仓库下载
  <mirrors>
    <mirror>
      <id>resoponsMirror</id>
      <mirrorOf>*</mirrorOf>
      <name>respositoresMirror</name>
      <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>

maven的生命周期

1.Clean生命周期一共包含了三个阶段:
pre-clean  执行一些需要在clean之前完成的工作
clean  移除所有上一次构建生成的文件
post-clean  执行一些需要在clean之后立刻完成的工作
2.compile
validate
generate-sources
process-sources
generate-resources
process-resources     复制并处理资源文件,至目标目录,准备打包。
compile     编译项目的源代码。

3.test
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources     复制并处理资源文件,至目标测试目录。
test-compile     编译测试源代码。
process-test-classes
test     使用合适的单元测试框架运行测试。这些测试代码不会被打包或部署。
prepare-package
package     接受编译好的代码,打包成可发布的格式,如 JAR 。
pre-integration-test
integration-test
post-integration-test
verify
install     将包安装至本地仓库,以让其它项目依赖。
deploy     将最终的包复制到远程的仓库,以让其它开发人员与项目共享。
      
5.site
pre-site     执行一些需要在生成站点文档之前完成的工作
site         生成项目的站点文档
post-site    执行一些需要在生成站点文档之后完成的工作,并且为部署做准备
site-deploy  将生成的站点文档部署到特定的服务器上
 

以上命令由插件 运行 每个都有自己的目标
Mojo 一个目标文件

常用插件
   <!-- 忽略测试 -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>

  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF8</encoding>
            </configuration>
      </plugin>

帮助命令:
  mvn help:describe -DgroupId=org.somewhere -DartifactId=some-plugin -Dversion=0.0.0
  mvn xxx -DskipTest=true  同样忽略测试

<!-- 生成测试覆盖率报告 -->
     <plugin> 
                <groupId>org.codehaus.mojo</groupId> 
                <artifactId>cobertura-maven-plugin</artifactId> 
                <version>2.5.1</version>
                <configuration>
                  <formats>
                    <format>xml</format>
                    <format>html</format>
                  </formats>
                </configuration>
                <executions>
                  <execution>
                    <id>cobertura-report</id>
                    <goals><goal>cobertura</goal></goals>
                    <phase>test</phase>
                  </execution>
                </executions>
            </plugin>
    
tomcat 插件
   <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat6-maven-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
        </plugin>
      </plugins>
    </pluginManagement>

启动命令:tomcat7:run

猜你喜欢

转载自zhangchuanlong-ai.iteye.com/blog/2212802