• 构建出自己的archetype-java脚手架


    进公司工作工作发现每个公司都有自己的脚手架来初始化项目,故也想开发一套自己的脚手架进行使用,会整合一些常用的东西,来解放双手

    步骤

    1. 创建出正常运行的项目
    2. parent的pom文件中添加插件
    
            
                
                    org.apache.maven.plugins
                    maven-archetype-plugin
                    3.2.1
                
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    3.8.1
                
            
        
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    1. 项目根目录下执行maven命令
    mvn archetype:create-from-project
    
    • 1
    1. target/generated-sourced/archetype目录下就是我们需要的项目模板
      删除不需要的文件,如idea等文件
    2. 切换到archetype目录执行maven命令,安装到本地
    mvn  clean install```
    6. 查看本地maven仓库地址,会有一个archetype-catalog.xml文件后打开后会有构建信息如:
    
    
    • 1
    • 2
    • 3
      com.yh.zq
    
      project-name
    
      1.0.0
    
      desc
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    7. 至此就创建成功了自定义的Archetype,可以通过命令从本地模板创建工程
    
    
    • 1
    • 2

    mvn archetype:generate -DarchetypeCatalog=local

    
    8. 上传Archetype到私服
    Archetype目录下的pom文件粘贴私服地址
    
    
    • 1
    • 2
    • 3
    • 4
    
        
            releases
            Nexus Release Repository
            xxxxx
        
        
            snapshots
            Nexus Snapshot Repository
            xxxx
        
    ```
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    执行maven部署命令

    mvn deploy
    
    • 1
    1. 通过本地命令使用脚手架
    mvn archetype:generate -DarchetypeCatalog=local
    
    • 1
    1. 通过私服使用脚手架
      切记不要使用powerShell打开执行会报错,使用cmd执行即可
      `` The goal you specified requires a project to execute but there is no POM in this directory (E:\ours\demo). Please verify you invoked Maven from the correct directory. -> [Hel
      p 1]```
      两者区别是前者指定了私服地址,后者指定了包名称
    mvn archetype:generate -DinteractiveMode=false -DgroupId=com.yh.zq -DartifactId=yh-demo-test -Dversion=1.0-SNAPSHOT -Dpackage=com.zq.yh -DarchetypeGroupId=yhlovezq.top -DarchetypeArtifactId=yh-archetype -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://n.qdedu.cn/nexus/content/repositories/snapshots/
    
    • 1
    mvn archetype:generate -DgroupId=com.free -DartifactId=demo-t -Dversion=1.0.0 -Dpackage=com.free.demo -DarchetypeGroupId=yhlovezq.top -DarchetypeArtifactId=yh-archetype -DarchetypeVersion=1.0-SNAPSHOT -DinteractiveMode=false
    
    
    • 1
    • 2

    参数说明:
    命令参数 介绍
    DgroupId 所需生成项目的groupId
    DartifactId 所需生成项目的artifactId
    Dversion 所需生成项目的version
    Dpackage 所需生成项目的包名
    DarchetypeGroupId Archetypal模板的groupId
    DarchetypeArtifactId Archetypal模板的artifactId
    DarchetypeVersion Archetypal模板的version
    DarchetypeRepository 私服地址
    12. 其他人通过maven命令使用该脚手架时候要么setting文件进行配置要么指定私服地址进行使用

    通过idea进行添加的方式不作赘述。

  • 相关阅读:
    【linux应用开发】
    如何在阿里云国际版上免费启动WordPress?
    BUUCTF【pwn】解题记录(4-6页持续更新中)
    分库分表及高可用搭建
    【并发编程】锁机制
    【嵌入式DIY实例-Nokia 5110显示LM35传感器数据
    Python网络编程之TCP编程
    springboot+vue+mysql+easyexcel实现文件导出+导出的excel单元格添加下拉列表
    极智开发 | git 命令行基本操作
    【IOS】oc中property属性值详解
  • 原文地址:https://blog.csdn.net/weixin_45466462/article/details/126299531