Maven 搭建 Archetype 项目

Maven 搭建 Archetype 项目

骨架项目发布

  1. 创建一个模板项目,如microApplication
  2. 在项目根路径下执行mvn archetype:create-from-project -X生成骨架项目$ROOT/target/generated-sources/archetype
  3. 配置$ROOT/target/generated-sources/archetypepom.xml
    1. 版本不能为快照版。如:不能是1.0-SNAPSHOT,可以是:RELEASES-1.0
    2. 配置发布地址
<distributionManagement>
    <repository>
      <!-- 这里的ID要和setting的id一致 -->
      <id>releases</id>
      <url>http://115.29.40.14:8010/nexus/content/repositories/thirdparty/</url>
    </repository>
    <!--这是打成快照版本的配置,如果不用这个snapshotRepository标签,打包失败,会报权限问题 -->
    <snapshotRepository>
      <id>snapshots</id>
      <url>http://115.29.40.14:8010/nexus/content/repositories/thirdparty/</url>
    </snapshotRepository>
  </distributionManagement>
  1. 修改骨架生成项目的规则文件$ROOT/target/generated-sources/archetype/src/mian/resources/META-INF/maven/archetype-metadata.xml(如:如何替换文本中值以及哪些值被替换)
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="yunti-micro-application"
                      xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <fileSets>
    <fileSet filtered="true" encoding="UTF-8">
      <directory></directory>
      <includes>
        <include>.classpath</include>
        <include>.project</include>
        <include>antx.properties</include>
        <include>.gitignore</include>
        <include>README.md</include>
      </includes>
    </fileSet>
  </fileSets>
  <modules>
    <module id="${rootArtifactId}-dao" dir="__rootArtifactId__-dao" name="${rootArtifactId}-dao">
      <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
      </fileSets>
    </module>
    <module id="${rootArtifactId}-sdk" dir="__rootArtifactId__-sdk" name="${rootArtifactId}-sdk">
      <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
      </fileSets>
    </module>
    <module id="${rootArtifactId}-service" dir="__rootArtifactId__-service" name="${rootArtifactId}-service">
      <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
          <directory>src/main/resources</directory>
          <includes>
            <include>**/*.xml</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
          <directory>src/test/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
          <directory>src/test/resources</directory>
          <includes>
            <include>**/*.xml</include>
          </includes>
        </fileSet>
      </fileSets>
    </module>
    <module id="${rootArtifactId}-web" dir="__rootArtifactId__-web" name="${rootArtifactId}-web">
      <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
          <directory>src/main/resources</directory>
          <includes>
            <include>**/*.xml</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
          <directory>src/main/webapp</directory>
          <includes>
            <include>**/*.jsp</include>
            <include>**/*.xml</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
          <directory>src/test/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
          <directory>src/test/resources</directory>
          <includes>
            <include>**/*.properties</include>
          </includes>
        </fileSet>
        <fileSet encoding="UTF-8">
          <directory>src/test/resources</directory>
          <includes>
            <include>**/*.md</include>
          </includes>
        </fileSet>
      </fileSets>
    </module>
  </modules>
</archetype-descriptor>
  1. $ROOT/target/generated-sources/archetype下执行mvn deploy -X -Dmaven.test.skip=true即可将骨架项目发布到远端

使用

idea

  1. 创建项目 new project -》maven

选择create from archetype并点击add archetype添加骨架模板配置(配置来源于生成骨架时的$ROOT/target/generated-sources/archetype/pom.xml配置中)

GroupId:com.yunti
ArtifactId:microApplication-archetype
Version:RELEASES-1.0
Repository(optional): ***
  1. 运行项目

依赖更新-》mvn install->tomcat7:run

  1. 提交项目

添加.gitignore文件

/antx.properties
/yunti-micro-application-dao/target
/yunti-micro-application-dao/*.project
/yunti-micro-application-dao/*.classpath
/yunti-micro-application-dao/.settings
/yunti-micro-application-sdk/target
/yunti-micro-application-sdk/*.project
/yunti-micro-application-sdk/*.classpath
/yunti-micro-application-sdk/.settings
/yunti-micro-application-service/target
/yunti-micro-application-service/*.project
/yunti-micro-application-service/*.classpath
/yunti-micro-application-service/.settings
/yunti-micro-application-web/target
/yunti-micro-application-web/*.project
/yunti-micro-application-web/*.classpath
/yunti-micro-application-web/.settings
*.classpath
*.project
.settings
target
/*.iml
/.idea
/src
*.iml
bin
rebel.xml
rebel-remote.xml
/.DS_Store
.DS_Store
*.rebel-remote.xml.bak
*.rebel.xml.bak
*.log

按仓库文档说明提交(注意:选择 HTTPS 方式)

# Software 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×