Maven 知识点总结

Maven 知识点总结
* man -v 查看maven版本
* compile 编译
* test 编译
* package 打包
* clean 删除target
* install 安装jar包到本地仓库

创建目录的两种方式:
1. archetype:generate 按照提示进行选择
2. archetype:generate -DgroupId=组织名,公司网址反写+项目名
-DartifactId=项目名-模块名
-Dversion=版本号
-Dpackage=代码所在包名

坐标(构建)
仓库(本地/远程仓库)
镜像仓库
中央仓库地址:maven 文件/lib/maven-model-builder…jar/org/…./pom-4.0.0.xml文件里

project>

  <modelVersion>4.0.0modelVersion>

  <repositories>
    <repository>
      <id>centralid>
      <name>Central Repositoryname>
<url>https://repo.maven.apache.org/maven2url>
      <layout>defaultlayout>
      <snapshots>
        <enabled>falseenabled>
      snapshots>
    repository>
  repositories>

镜像仓库(无法访问外网,国内镜像仓库)
打开maven文件/conf/setting.xml 修改为国内China镜像仓库

  
    -- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    
      maven.net.cn
      central
      central mirror in China
       http://maven.net.cn/content/groups/public
    
     —>
  

更改仓库默认路径

打开maven文件/conf/setting.xml

-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  /path/to/local/repo
  —>
  • 某路径下新建repo文件夹,将 /path/to/local/repo更改为该路径;
  • 复制settings.xml文件,至repo文件夹下。以后每次更新,就不需要重新修改settings.xml文件了。

maven生命周期
clean.compile.test.package.install
清理,编译,测试,打包,集成测试,验证,部署
(maven抽象出一套项目的生命周期,而插件是对maven抽象的具体实现)
clean 清理项目
1. pre-clean 执行清理前的工作
2. clean 清理上一次构建生成的所有文件
3. post-clean 执行清理后的文件
default 构建项目
1. compile
2. test
3. package
4. install
site 生成项目站点
1. pre-site 在生成站点前要完成的工作
2. site 生成项目的站点文档
3. post-site 在生成项目站点后要完成的工作
4. site-depoly 发布生成的站点到服务器上

pom.xml常用标签

"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/maven-v4_0_0.xsd”>
      
    4.0.0
反写公司网址+项目名称
项目名称+模块名
<!—
        第一个0表示大版本号,第二个0表示分之版本号,第三0表示小版本号
        snapshot 快照
        alpha 内部测试
        beta 公测
        Release 稳定
        GA 正式发布
—>
    <version>0.0.1_NAPSHOTversion>
<!—
    默认jarwarzippom)
—>
<package>package>

    <dependencies>
        <dependency>
             <groupId>junitgroupId>
             <artifactId>junitartifactId>
             <version>4.10version>
        dependency>
    dependencies>
   <name>项目描述名name>
    <url>项目地址url>
    <description>项目描述description>
    <developers>开发人员列表developers>

project>
依赖范围
<scope>scope>
1. compile
2. provided
3. runtime
4. test
5. system
6. import
依赖传递
                                        ——————————全文完——————————
                                                                                                          2017年2月26日 上午10:15

你可能感兴趣的:(个人经验)