1. 为什么要使用maven?

毕业开始工作,项目组用的maven-spring开发的,不得不了解一下,看过很多介绍,其中maven最大的特点就是

        管理jar包和版本管理

  (参考:https://www.cnblogs.com/zhangxh20/p/5134812.html

2.导入maven工程

  

 

导入工程本身不难,大多数工程与工程是相互依赖的,在编译运行的时候就容易会报错,批量将工程导入之后,逐个编译,在逐个运行,能减少因为项目依赖报错

其次的话,maven工程大多数都是通过pom.xml文件来管理的,所以了解pom.xml对学习maven很重要

(参考:https://www.cnblogs.com/xiaobaizhiqian/p/8214035.html

  pom.xml    

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
            http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <!-- 基本配置 -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>...</groupId>                组别,一般为域名的反写
  <artifactId>...</artifactId>      项目名, 在Maven中查找类和方法或配置文件时就是以groupId和artifactId为坐标来进行的
  <version>...</version>                版本号,为了管理工程的版本,在引用依赖时,版本号也是不可缺少的,错误的版本号带来的麻烦。。。
  <packaging>...</packaging>       打包方式:一般父工程是以pom方式打包,子工程依赖于父工程以jar方式打包,一般在子工程的pom.xml里不会写这个标签对

    <!-- 依赖配置 -->             在maven repository中查找依赖的按1.本地仓库、2.中央仓库、3.远程仓库的顺位查找目标jar
  <dependencies>                
    <groupId>...</groupId>        依赖过程中需要指明依赖的jar包域名、jar包名称以及版本号
    <artifactId>...</artifactId>
    <version>...</version>
  </dependencies>   
    <parent>...</parent>          父工程依赖  一般在子项目中出现,由父项目的pom.xml同一管理某些公共jar包的banbenhgai
    <dependencyManagement>...</dependencyManagement>
    <modules>...</modules>
    <properties>...</properties>

    <!-- 构建配置 -->
    <build>...</build>
    <reporting>...</reporting>

    <!-- 项目信息 -->
    <name>...</name>
    <description>...</description>
    <url>...</url>
    <inceptionYear>...</inceptionYear>
    <licenses>...</licenses>
    <organization>...</organization>
    <developers>...</developers>
    <contributors>...</contributors>

    <!-- 环境设置 -->
    <issueManagement>...</issueManagement>
    <ciManagement>...</ciManagement>
    <mailingLists>...</mailingLists>
    <scm>...</scm>
    <prerequisites>...</prerequisites>
    <repositories>...</repositories>
    <pluginRepositories>...</pluginRepositories>
    <distributionManagement>...</distributionManagement>
    <profiles>...</profiles>
</project>

 3. maven工程 clean compile install记忆update。

  • clean,执行该命令会删除项目路径下的target文件,但是不会删除本地的maven仓库已经生成的jar文件
  • compile,编译命令,会在项目路径下生成一个target目录,在该目录中包含一个classes文件夹,里面全是生成的class文件及字节码文件
  • package,这个命令会在你的项目路径下一个target目录,并且拥有compile命令的功能进行编译,同时会在target目录下生成项目的jar/war文件
  • install,该命令包含了package命令功能,不但会在项目路径下生成class文件和jar包,同时会在你的本地maven仓库生成jar文件,供其他项目使用

所以正常编译项目只需要install就可以了

(参考:https://www.bbsmax.com/A/WpdKmGRAJV/

update project:当maven工程有结构上的变化时(pom文件或者*.classpath文件发生变化时),通常需要用更新工程的手段来新增或者修改相关文件。

posted on 2019-08-26 17:30  无心工作只想偷懒  阅读(159)  评论(0编辑  收藏  举报