maven学习笔记

maven 配置:
  1、配置系统变量MAVEN_HOME(maven解压路径)
  2、配置path(添加maven的bin所在路径)

maven基础命令:在pom.xml所在的文件位置运行命令
  mvn compile 编译main目录中的java文件,会生成一个target文件夹里面是class文件
  mvn test 测试
  mvn package 打包命令,打成jar/war包
  mvn install 将开发的模块放入本地仓库,供其他模块使用(不同项目沟通的基础)
  mvn clean 删除编译的文件(target文件夹)

  deploy :一键部署命令

eclipse:创建maven项目建议添加自己下载的maven:window-preferences-installations,且修改user
  settings,让其识别自己的maven仓库设置
  运行:右击pom-run-build...-Goals(输入命令单词)-run

仓库:
  远程仓库-公司私服-本地仓库(先从这里寻找资源)

pom文件中增加新的依赖:
  要进行update这一操作 项目名-maven-update

排除依赖:
  不要该依赖中的某些部分
  <dependency>
  <groupId>commons-fileupload</groupId>
  <artifactId>commons-fileupload</artifactId>
  <exclusions>
  <exclusion>
  <groupId>...</groupId><artifactId></artifactId>
  </exclusion>
  </exclusions>
  <version>1.3.1</version>
  </dependency>

依赖传递原则:
  依赖可以传递(a依赖c;d依赖a,c;d可以不用写c,但是a中的c的<scope>必须是compile
  距离最短优先(a中有依赖b,c中有依赖b,a依赖c,a会使用自己里面的b)
  不同的pom相同的依赖,前面的覆盖后面的依赖版本
  同一pom,同一依赖不同版本出现时,后面声明的依赖会覆盖前面的依赖(严禁使用)

依赖继承:
  第一步:声明父类 新建maven项目,打包方式选择pom方式
  <dependencyManagement>
  <dependencies>
  <dependency>
  。。。
  </dependency>
  </dependencies>

  </dependencyManagement>
  二:子类中说明继承关系
  <parent>
  <groupId>G001</groupId>
  <artifactId>peple</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <relativePath>../peple/pom.xml</relativePath>
  </parent>
  三:声明继承父类的某些依赖:
  <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  </dependency>

maven聚合(减少针对每个maven的install操作):
  前提:modules必须配置在pom打包方式的maven项目中
  <modules>
  <module>../addr</module>
  <module>../time1</module>
  </modules>

pom.xml的properties用法:
  <properties>
  <xxxversion>4.0</xxxversion>
  </properties>
  在此pom中的标签可使用<>${xxxversion}</>

maven web项目:
  1、打包方式选war方式
  2、右击项目--buildpath-libraries--add...---serverruntime--tomcat8.5(或在pom加入server-api的依赖)
  3、手动在webapp中添加WEB-INF/web.xml、index.jsp...
  4、将war包复制到tomcat/webapps中
  注意不用建立lib包,因为jar包管理由maven pom实现
  启动服务:tomcat/bin/startup批处理文件
  即可访问

原文地址:https://www.cnblogs.com/qinyios/p/10294807.html