zoukankan      html  css  js  c++  java
  • maven archetype二三事

    maven plugin

    创建maven archetype 骨架的plugin是
    xml

    org.apache.maven.plugins
    maven-archetype-plugin
    ${maven-archetype-plugin.version}

    ${source.encoding}
    ${jdk.version}
    ${jdk.version}

    
    关于maven archetype的详细介绍参考:https://maven.apache.org/archetype/maven-archetype-plugin/plugin-info.html
    
    
    ## 从项目中创建骨架
    > mvn archetype:create-from-project
    
    上面的命令是最简单的命令,maven会自己根据设定的规则进行创建。
    但有些时候,maven没有那么智能,比如它取当前project的packagename的时候,会取最短的包名作为包名的占位符,在最后生成的archetype中进行占位。
    此时,需要手动指定当前项目模板的packagename替换maven自己选择的packageName。命令如下:
    >mvn archetype:create-from-project -DpackageName=cn.edu.lizhao
    
    除此之外,archetype插件还有其它参数,详情参考maven官方声明:https://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html
    >The create-from-project goal enable the user to provide some sensible configuration using the system properties or a property file.The system properties permits the user to define the groupId, artifactId, version of the created archetype. They also permits to override the resolved package and to create a partial archetype.When used, the property file takes precedence over the system properties. It is also the only way to define additional properties in the archetype.
    来源: https://maven.apache.org/archetype/maven-archetype-plugin/advanced-usage.html
    
    ## 将创建的archetype安装到本地
    >mvn install
    >mvn archetype:crawl   //更新索引
    
    此命令需要进入到:
    >	argetgenerated-sourcesarchetype
    
    ## 原理猜想
    在执行从archetype:create-from-project的时候,maven会自己根据设定的规则,提取出一个新的项目,这个项目也是maven项目,只是相关的代码会增加占位符,同时项目的打包方式改为`maven-archetype`。至此archetype插件的任务就完成了。之后就是普通的install、deploy等。maven主程序根据packaging的方式进行打包,并在install的时候更新archetypecatalog,这样就可以找到该archetype了。
    因此,需要学习的点:
    1. archetype插件在create-from-project的时候设定了哪些规则,这部分可以通过看源码了解,或者通过插件配置的参数大概猜一下
    2. 对archetype的goal等的用法熟练使用
    
    ## 将创建的archetype发布到私服
    >mvn deploy
    这一步需要配置好pom文件的distribute相关节点,具体可以参考mvn deploy相关资料。
    
    ## 用archetype生成项目
    >mvn archetype:generate
    这一步只是archetype插件的generate goal,具体参数可以参考前面的链接。
  • 相关阅读:
    Ubuntu-12.04.5 安装 oracle 12.2.0.1 数据库database软件
    Ubuntu-12.04.5 再再再次安装 oracle 11.2.0.4 数据库database软件(又不一样了!)
    Ubuntu-4.10 安装 oracle 11.2.0.4 数据库database软件(最古老的ubuntu)
    PATH add
    可望不可即 可望不可及
    天干地支
    24节气
    二进制、十进制和十六进制转换器
    信用卡三磁道
    ISO8583
  • 原文地址:https://www.cnblogs.com/lzxianren/p/maven-archetype-plugin.html
Copyright © 2011-2022 走看看