zoukankan      html  css  js  c++  java
  • 项目管理利器-maven

    1:添加MAVEN_HOME环境变量 值为安装的maven路径,添加系统变量path值为%MAVEN_HOME%in

    2:mvn compile编译

    mvn test 测试
    mvn package打包
    mvn clean 删除target文件夹
    mvn install 安装jar包到本地仓库

     mvn package -Dmaven.test.skip=true 跳过测试

    3:命令行创建项目

       1:mvn archetype:generate -DgroupId=com.cj  -DartifactId=webAppDemo -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false 

    2:mvn archetype:generate 按照提示选择

    4:在settings.xml中配置镜像仓库地址

    <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
    </mirror>

    5:在settings.xml配置本地仓库地址

    <localRepository>/Users/usename/.m2/repository</localRepository>

    6:通常会把settings.xml拷贝一份 以防升级maven 覆盖掉

    7:maven生命周期

                  clean清理项目

    pre-clean 执行一些需要在clean之前完成的工作
    clean 移除所有上一次构建生成的文件
    post-clean 执行一些需要在clean之后立刻完成的工作

    default构建项目

    compile test package install


    site生成项目站点

    pre-site 执行一些需要在生成站点文档之前完成的工作
    site 生成项目的站点文档
    post-site 执行一些需要在生成站点文档之后完成的工作,并且为部署做准备
    site-deploy 将生成的站点文档部署到特定的服务器上

     

     

     8:

    <modelVersion>4.0.0</modelVersion>当前pom版本
    <groupId></groupId>反写公司网址+项目名
    <artifactId></artifactId>项目名+模块名
    <packaging>jar</packaging>默认是jar包
    <version>0.0.1-SNAPSHOT</version>大版本+分支版本+小版本号 SNAPSHOT快照版本,alpha内部测试,beta公测,release 稳定,GA正式发布
    <name>demo</name>项目描述名
    <description>Demo project for Spring Boot</description>项目描述名
    <url></url>项目地址
    <developers></developers>开发人员
      <organization>     
         <!--组织的全名-->    
            <name>demo</name>     
            <!--组织主页的URL-->    
            <url>http://www.baidu.com/banseon</url>     
        </organization> 

    9:maven 有编译测试运行三个阶段

    <scope>compile</scope> 默认的范围,编译测试运行三个阶段都有效

    <scope>provided</scope>编译测试阶段都有效

    <scope>runtime</scope> 测试运行阶段都有效

    <scope>test</scope> 测试阶段都有效

    <scope>system</scope>编译测试阶段都有效和provided类似 只是和本机系统有关,可移植性差

    <scope>import</scope>

    在<dependencyManagement>管理下的dependencies多了一种scope——import。

    这种scope仅用于type为"pom"的dependency,其意义为引入该dependency的pom中定义的所有dependency定义。

    10:在mavenB项目中引入mavenA项目依赖,通过依赖传递,会将mavenA中的jar包传递进来

    如果B中不需要A中的某个jar包就可以使用以下标签:

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
    <exclusions>
    <exclusion>
    <artifactId>commons-logging</artifactId>
    <groupId>commons-logging</groupId>
    </exclusion>
    </exclusions>
    </dependency>
    11:如何修改maven的默认jdk版本

    在maven的安装目录找到settings.xml文件,在里面添加如下代码

    <profile>
        <id>jdk1.6</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.6</jdk>
        </activation>
        <properties>
            <!-- want to use the Java 8 language features, Default 1.5 -->
            <maven.compiler.source>1.6</maven.compiler.source>
            <!-- want the compiled classes to be compatible with JVM 1.8, Default 1.5 -->
            <maven.compiler.target>1.6</maven.compiler.target>
            <!-- Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true -->
            <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
        </properties>
    </profile> 

    12:依赖冲突的解决

    1).短路优先原则
    A->B->logback-1.0.jar
    A->logback-1.1.jar

    2).先声明先优先原则(先解析先引用)
    与项目A pom中配置 引用坐标的顺序有关,如果依赖B在C前的话 就优先B,反之...
    A->B->logback-1.0.jar
    A->C->logback-1.1.jar

    13:<modules>标签详解

    此标签在父工程的pom.xml中表示子模块的位置,标签内元素为<module>。以当前父工程所在的文件夹为基准,<module>中填写子模块的相对路径。在Maven build app-parent的时候,它会根据子模块的相互依赖关系整理一个build顺序,然后依次build。所有带有子模块的项目的packaging都为pom

    14;dependencyManagement和dependencies区别

    dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)
    dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。

    15:package后启动


    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <executions>
    <execution>
    <phase>package</phase>
    <goals>
    <goal>run</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
    </plugin>

    16:tomcat7 启动

    <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
    <path>/taobao</path>
    <port>9090</port>
    <uriEncoding>UTF-8</uriEncoding>
    </configuration>
    </plugin>

    17:mvn jetty:run

    <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.2.v20140723</version>
    </plugin>

     18:三种启动方式 

    java -jar 启动方式如下

    java -jar test.jar即可以运行这个jar。
    java -jar test.war即可以运行这个war。

    maven插件启动方式如下

    mvn spring-boot:run

    idea 启动方式

  • 相关阅读:
    图像滤镜艺术---乐高像素拼图特效滤镜的代码实现
    假设你也23
    seajs载入流程图
    android 怎样将主菜单图标改成按安装时间排序
    热力学第一定律的社会学思考
    Django创建数据表
    KeyPress 和KeyDown 、KeyPress之间的区别
    Delphi 制作自定义数据感知控件并装入包(dpk文件)中(与DBText类似的数据感知控件)
    Delphi中的窗体创建与销毁
    Delphi ADOQuery连接数据库的查询、插入、删除、修改
  • 原文地址:https://www.cnblogs.com/zyy1688/p/10267623.html
Copyright © 2011-2022 走看看