β

《Maven官方指南》模型指南

并发编程网 – ifeve.com 25 阅读

原文链接 译者:carvendy

模型指南

模型 是一个从简单模板生成源码的工具。从简单模板你可以生成这些:

一个经典类型模型模板如下:

<model xmlns="http://modello.codehaus.org/MODELLO/1.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://modello.codehaus.org/MODELLO/1.4.0 http://modello.codehaus.org/xsd/modello-1.4.0.xsd"
  xml.namespace="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/${version}"
  xml.schemaLocation="http://maven.apache.org/xsd/archetype-${version}.xsd">
  <id>archetype</id>
  <name>Archetype</name>
  <description>
    <![CDATA[Maven's model for the old archetype descriptor (ie for Archetype 1.0.x).
    <p>The metadata about an archetype is stored in the <code>archetype.xml</code> file located
    in the <code>META-INF/maven</code> directory of its jar file.</p>]]>
  </description>
 
  <defaults>
    <default>
      <key>package</key>
      <value>org.apache.maven.archetype.model</value>
    </default>
  </defaults>
 
  <classes>
    <class rootElement="true" xml.tagName="archetype">
      <name>ArchetypeModel</name>
      <description>Describes the assembly layout and packaging.</description>
      <version>1.0.0</version>
      <fields>
        <field>
          <name>id</name>
          <version>1.0.0</version>
          <required>true</required>
          <type>String</type>
          <description><![CDATA[The value should be the same as the artifactId in the archetype <code>pom.xml</code>.]]></description>
        </field>
        <field>
          <name>allowPartial</name>
          <version>1.0.0</version>
          <type>boolean</type>
          <description><![CDATA[Setting this option to <code>true</code> makes it possible to run the
            <code>archetype:create</code> even on existing projects.]]></description>
        </field>
 
        <field xdoc.separator="blank">
          <name>sources</name>
          <version>1.0.0</version>
          <description><![CDATA[Files that will go into <code>src/main/java</code>.]]></description>
          <association>
            <type>Source</type>
            <multiplicity>*</multiplicity>
          </association>
        </field>
        <field>
          <name>resources</name>
          <version>1.0.0</version>
          <description><![CDATA[Files that will go into <code>src/main/resources</code>.]]></description>
          <association>
            <type>Resource</type>
            <multiplicity>*</multiplicity>
          </association>
        </field>
 
        <field xdoc.separator="blank">
          <name>testSources</name>
          <version>1.0.0</version>
          <description><![CDATA[Files that will go into <code>src/test/java</code>.]]></description>
          <association xml.tagName="source">
            <type>Source</type>
            <multiplicity>*</multiplicity>
          </association>
        </field>
        <field>
          <name>testResources</name>
          <version>1.0.0</version>
          <description><![CDATA[Files that will go into <code>src/test/resources</code>.]]></description>
          <association xml.tagName="resource">
            <type>Resource</type>
            <multiplicity>*</multiplicity>
          </association>
        </field>
 
        <field xdoc.separator="blank">
          <name>siteResources</name>
          <version>1.0.0</version>
          <description><![CDATA[Files that will go into <code>src/site</code>.]]></description>
          <association xml.tagName="resource">
            <type>Resource</type>
            <multiplicity>*</multiplicity>
          </association>
        </field>
      </fields>
    </class>
 
    <class>
      <name>Source</name>
      <description>Describes a source file. Note that source files are always filtered, unlike resources that
        can be non-filtered.</description>
      <version>1.0.0</version>
      <fields>
        <field xml.content="true">
          <name>file</name>
          <version>1.0.0</version>
          <type>String</type>
          <description><![CDATA[The source file.]]></description>
        </field>
        <field xml.attribute="true">
          <name>encoding</name>
          <version>1.0.0</version>
          <type>String</type>
          <description><![CDATA[The encoding to be used when reading/writing this file.
            Platform encoding is used by default, or ISO-8859-1 when filename ends in <code>.properties</code>]]></description>
        </field>
      </fields>
    </class>
    <class>
      <name>Resource</name>
      <description>Describes a resource file.</description>
      <version>1.0.0</version>
      <fields>
        <field xml.content="true">
          <name>file</name>
          <version>1.0.0</version>
          <type>String</type>
          <description><![CDATA[The resource file.]]></description>
        </field>
        <field xml.attribute="true">
          <name>encoding</name>
          <version>1.0.0</version>
          <type>String</type>
          <description><![CDATA[The encoding to be used when reading/writing this file.
            Platform encoding is used by default, or ISO-8859-1 when filename ends in <code>.properties</code>]]></description>
        </field>
        <field xml.attribute="true">
          <name>filtered</name>
          <version>1.0.0</version>
          <type>boolean</type>
          <defaultValue>true</defaultValue>
          <description>A resource can be filtered, which means the file will be used as Velocity template.
          It can be non-filtered, which means the file will be copied without modification.</description>
        </field>
      </fields>
    </class>
  </classes>
</model>

为了利用模型你要配置 maven-modello-plugin 的一些东西,你想生成java源码模型,有xpp3序列化源码和xpp3反序列源码:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.modello</groupId>
        <artifactId>modello-maven-plugin</artifactId>
        <version>1.8.3</version>
        <executions>
          <execution>
            <goals>
              <!-- Generate the xpp3 reader code -->
              <goal>xpp3-reader</goal>
              <!-- Generate the xpp3 writer code -->
              <goal>xpp3-writer</goal>
              <!-- Generate the Java sources for the model itself -->
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <models>
            <model>src/main/mdo/descriptor.mdo</model>
          </models>
          <version>1.0.0</version>
          <useJava5>true</useJava5>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

原创文章,转载请注明: 转载自 并发编程网 – ifeve.com 本文链接地址: 《Maven官方指南》模型指南

魔术师Carvendy

尘世间一小小Javaer ,喜欢coding和思考。

Latest posts by 魔术师Carvendy ( see all )

Favorite Loading 添加本文到我的收藏

Related posts:

  1. 《Maven官方指南》Maven 类加载指南
  2. 《Maven官方指南》 迁移引导
  3. 《Maven官方指南》生成源文件
  4. 《Maven官方指南》翻译邀请
  5. 《Maven官方指南》jdk1.4项目使用JDK1.5构建指南
  6. 《Maven官方指南》创建装配
  7. 《Maven官方指南》Maven 配置
  8. 《Maven官方指南》配置档案插件指南
  9. 《Maven官方指南》权限和发布设置
  10. 《Maven官方指南》Maven使用Ant指南
  11. 《Maven官方指南》使用扩展
  12. 《Maven官方指南》构建Maven
  13. 《Maven官方指南》APT格式
  14. 《Maven官方指南》片段宏指南
  15. 《Maven官方指南》30分钟入门
作者:并发编程网 – ifeve.com
让天下没有难学的技术
原文地址:《Maven官方指南》模型指南, 感谢原作者分享。

发表评论