如何使多模块项目中的原型使用基于artifactId 的目录?

发布于 2024-11-24 10:37:06 字数 5257 浏览 1 评论 0原文

我已经使用 archetype:create-from-project 从多模块项目中创建了一个原型。

archetype-metadata.xml 如下所示,我想要的是当我运行 mvn archetype:generate 时可以使用我提供的 archetypeId 而不是使用固定目录来修改“dir”。可以吗?

 <?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="service-parent"
     xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <modules>
     <module id="service-def" dir="service-def" name="service-def">
       <fileSets>
         <fileSet filtered="true" packaged="true" encoding="UTF-8">
           <directory>src/main/java</directory>
           <includes>
             <include>**/*.java</include>
           </includes>
         </fileSet>
       </fileSets>
     </module>
     <module id="service" dir="service" name="service">
       <fileSets>
         <fileSet filtered="true" packaged="true" encoding="UTF-8">
           <directory>src/main/java</directory>
           <includes>
             <include>**/*.java</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>
             <include>**/*.properties</include>
           </includes>
         </fileSet>
         <fileSet encoding="UTF-8">
           <directory>src/test/resources</directory>
           <includes>
             <include>**/*.sql</include>
             <include>**/*.dtd</include>
           </includes>
         </fileSet>
       </fileSets>
     </module>
     <module id="service-web" dir="service-web" name="service-web">
       <fileSets>
         <fileSet filtered="true" encoding="UTF-8">
           <directory>src/main/webapp</directory>
           <includes>
             <include>**/*.xml</include>
           </includes>
         </fileSet>
         <fileSet filtered="true" encoding="UTF-8">
           <directory>src/main/resources</directory>
           <includes>
             <include>**/*.xml</include>
           </includes>
         </fileSet>
       </fileSets>
     </module>
   </modules>
 </archetype-descriptor>

这是原型的结构:

 ├── pom.xml
 └── src
     ├── main
     │   └── resources
     │       ├── archetype-resources
     │       │   ├── pom.xml
     │       │   ├── service
     │       │   │   ├── pom.xml
     │       │   │   └── src
     │       │   │       ├── main
     │       │   │       │   └── java
     │       │   │       └── test
     │       │   │           ├── java
     │       │   │           └── resources
     │       │   ├── service-def
     │       │   │   ├── pom.xml
     │       │   │   └── src
     │       │   │       └── main
     │       │   │           └── java
     │       │   └── service-web
     │       │       ├── pom.xml
     │       │       └── src
     │       │           └── main
     │       │               ├── resources
     │       │               │   ├── dao-context.xml
     │       │               │   ├── hibernate.cfg.xml
     │       │               │   └── single-context.xml
     │       │               └── webapp
     │       │                   └── WEB-INF
     │       │                       ├── jboss-web.xml
     │       │                       ├── remoting-servlet.xml
     │       │                       └── web.xml
     │       └── META-INF
     │           └── maven
     │               └── archetype-metadata.xml
     └── test
         └── resources
             └── projects
                 └── basic
                     ├── archetype.properties
                     └── goal.txt

I have create an archetype using archetype:create-from-project out of a multi module project.

The archetype-metadata.xml is like below, what I would want is that the "dir" can be modified when I run mvn archetype:generate by using the archetypeId I provide instead of using a fixed dir. Can that be done?

 <?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="service-parent"
     xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <modules>
     <module id="service-def" dir="service-def" name="service-def">
       <fileSets>
         <fileSet filtered="true" packaged="true" encoding="UTF-8">
           <directory>src/main/java</directory>
           <includes>
             <include>**/*.java</include>
           </includes>
         </fileSet>
       </fileSets>
     </module>
     <module id="service" dir="service" name="service">
       <fileSets>
         <fileSet filtered="true" packaged="true" encoding="UTF-8">
           <directory>src/main/java</directory>
           <includes>
             <include>**/*.java</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>
             <include>**/*.properties</include>
           </includes>
         </fileSet>
         <fileSet encoding="UTF-8">
           <directory>src/test/resources</directory>
           <includes>
             <include>**/*.sql</include>
             <include>**/*.dtd</include>
           </includes>
         </fileSet>
       </fileSets>
     </module>
     <module id="service-web" dir="service-web" name="service-web">
       <fileSets>
         <fileSet filtered="true" encoding="UTF-8">
           <directory>src/main/webapp</directory>
           <includes>
             <include>**/*.xml</include>
           </includes>
         </fileSet>
         <fileSet filtered="true" encoding="UTF-8">
           <directory>src/main/resources</directory>
           <includes>
             <include>**/*.xml</include>
           </includes>
         </fileSet>
       </fileSets>
     </module>
   </modules>
 </archetype-descriptor>

This is the structure of the archetype:

 ├── pom.xml
 └── src
     ├── main
     │   └── resources
     │       ├── archetype-resources
     │       │   ├── pom.xml
     │       │   ├── service
     │       │   │   ├── pom.xml
     │       │   │   └── src
     │       │   │       ├── main
     │       │   │       │   └── java
     │       │   │       └── test
     │       │   │           ├── java
     │       │   │           └── resources
     │       │   ├── service-def
     │       │   │   ├── pom.xml
     │       │   │   └── src
     │       │   │       └── main
     │       │   │           └── java
     │       │   └── service-web
     │       │       ├── pom.xml
     │       │       └── src
     │       │           └── main
     │       │               ├── resources
     │       │               │   ├── dao-context.xml
     │       │               │   ├── hibernate.cfg.xml
     │       │               │   └── single-context.xml
     │       │               └── webapp
     │       │                   └── WEB-INF
     │       │                       ├── jboss-web.xml
     │       │                       ├── remoting-servlet.xml
     │       │                       └── web.xml
     │       └── META-INF
     │           └── maven
     │               └── archetype-metadata.xml
     └── test
         └── resources
             └── projects
                 └── basic
                     ├── archetype.properties
                     └── goal.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城凉梦凉人心 2024-12-01 10:37:06

您需要使用 rootArtifactId 占位符,例如:

 <?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="service-parent"
 xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <modules>
   <module id="${rootArtifactId}-def" dir="__rootArtifactId__-def" name="${rootArtifactId}-def">
     <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}" dir="__rootArtifactId__" name="${rootArtifactId}">
     <fileSets>
       <fileSet filtered="true" packaged="true" encoding="UTF-8">
       <directory>src/main/java</directory>
       <includes>
         <include>**/*.java</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>
         <include>**/*.properties</include>
       </includes>
     </fileSet>
     <fileSet encoding="UTF-8">
         <directory>src/test/resources</directory>
         <includes>
           <include>**/*.sql</include>
           <include>**/*.dtd</include>
         </includes>
       </fileSet>
     </fileSets>
   </module>
   <module id="${rootArtifactId}-web" dir="__rootArtifactId__-web" name="${rootArtifactId}-web">
     <fileSets>
       <fileSet filtered="true" encoding="UTF-8">
         <directory>src/main/webapp</directory>
         <includes>
           <include>**/*.xml</include>
         </includes>
       </fileSet>
       <fileSet filtered="true" encoding="UTF-8">
         <directory>src/main/resources</directory>
          <includes>
           <include>**/*.xml</include>
         </includes>
       </fileSet>
     </fileSets>
   </module>
 </modules>

使用 __rootArtifactId__ 前缀重命名模块文件夹。

您可以在 http://code.google.com/p/open-archetypes/source/browse/multi-javaee5-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

You need to use the rootArtifactId placeholder such as :

 <?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="service-parent"
 xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <modules>
   <module id="${rootArtifactId}-def" dir="__rootArtifactId__-def" name="${rootArtifactId}-def">
     <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}" dir="__rootArtifactId__" name="${rootArtifactId}">
     <fileSets>
       <fileSet filtered="true" packaged="true" encoding="UTF-8">
       <directory>src/main/java</directory>
       <includes>
         <include>**/*.java</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>
         <include>**/*.properties</include>
       </includes>
     </fileSet>
     <fileSet encoding="UTF-8">
         <directory>src/test/resources</directory>
         <includes>
           <include>**/*.sql</include>
           <include>**/*.dtd</include>
         </includes>
       </fileSet>
     </fileSets>
   </module>
   <module id="${rootArtifactId}-web" dir="__rootArtifactId__-web" name="${rootArtifactId}-web">
     <fileSets>
       <fileSet filtered="true" encoding="UTF-8">
         <directory>src/main/webapp</directory>
         <includes>
           <include>**/*.xml</include>
         </includes>
       </fileSet>
       <fileSet filtered="true" encoding="UTF-8">
         <directory>src/main/resources</directory>
          <includes>
           <include>**/*.xml</include>
         </includes>
       </fileSet>
     </fileSets>
   </module>
 </modules>

Rename your module folders using the __rootArtifactId__ prefix.

You can see an example of such archetype in http://code.google.com/p/open-archetypes/source/browse/multi-javaee5-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文