学习是件开心事

搭建项目骨架

将本地服务做成骨架 方便以后创建项目

脚手架里生成项目

懒的从0开始搭建项目了,直接从其他优秀的脚手架里生成最简洁的springboot项目,https://start.spring.io/ (官网)和https://start.aliyun.com/(阿里),2个地址都可以生成。

本地生成骨架

1 项目的根pom文件里添加archetype的maven插件

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.2</version>
</plugin>

2 根pom.xml同级的目录下运行以下命令以生成骨架

mvn clean archetype:create-from-project

3 上步骤会在项目里生成target目录
Image text

4 将骨架install到本地

cd target/generated-sources/archetype/
mvn clean install

5 根pom.xml同级的目录下运行以下命令以生成坐标信息

mvn archetype:crawl

这个时候在本地的maven仓库中就会生成一个archetype-catalog.xml文件,里面有固件的坐标信息。

6 执行命令以根据骨架生成项目

mvn archetype:generate -DarchetypeCatalog=local

上传骨架到nexus

1 在项目target/generated-sources/archetype/pom.xml 中加入以下配置,指定nexus地址。

<distributionManagement>
 <repository>
    <id>nexus-releases</id>
    <name>Micaicms Releases</name>
    <url>http://localhost:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
    <id>nexus-snapshots</id>
    <name>Micaicms Releases</name>
    <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

2 然后在target/generated-sources/archetype运行

mvn deploy

使用远程nexus仓库的archetype创建项目

使用远程nexus仓库的archetype创建项目的时候,必须在自己的maven conf 下settings.xml加入以下配置:

<profile>
      <!-- the profile id is arbitrary 这个id是任意填的--> 
      <id>my_archetype</id>
      <repositories>
        <repository>
          <!-- the repository id has to be named: archetype 这repository Id必须是archetype -->
          <id>archetype</id>
          <name>my archetypes</name>
          <url>http://127.0.0.1:8081/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
            <checksumPolicy>fail</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <checksumPolicy>warn</checksumPolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>

  <activeProfiles>
    <activeProfile>my_archetype</activeProfile> <!-- 这个id是上面的profile id -->
  </activeProfiles>