代码之家  ›  专栏  ›  技术社区  ›  Malax

从包含多个和可选模块的Maven项目构建任意Ditribution

  •  2
  • Malax  · 技术社区  · 16 年前

    首先:我的专业知识有限,所以请你耐心听我说。;-)我有一个简单的Maven项目,目前由三个模块组成。包含应用程序核心的模块称为核心(创意名称,哈?:-)和其他模块基本上都是这个核心模块的插件。有一个限制:只能向核心模块添加一个插件。

    核心模块有自己的SpringIOC配置,减去插件配置。这很简单:核心代码将读取一个名为“plugin”的bean,该bean在核心配置中没有定义。插件模块将提供自己的配置文件,该文件将提供一个名为“plugin”的bean,然后由核心代码使用。这非常适合我的用例。

    我想提供管理,它将部署系统,一个简单的方法来构建包含核心的分发,一个选定的插件和一个合理的默认配置。也许是 tar.gz 或者类似的。我不希望他挖掘我的SpringIOC文件,将它们复制在一起,等等。实际配置(如TCP/IP端口)是在属性文件中完成的。

    为了澄清我的意思,我构建了一个示例结构。请注意,文件名仅用于解释目的。

    /bin/core.jar [Build from core module]  
    /bin/plugin.jar [Build from a plugin module]
    
    /lib-bin/library-required-by-plugin.jar [Dependency resolved by maven + copy]
    /lib-bin/library-required-by-core.jar [Dependency resolved by maven + copy]
    /lib-bin/another-library-required-by-core.jar [Dependency resolved by maven + copy]
    
    /etc/spring/core-beans.xml [Copied from core module /etc/]
    /etc/spring/plugin.xml [Copied from plugin module /etc/]
    /etc/default-core-config.properties [Copied from core module /etc/]
    /etc/default-plugin-config.properties [Copied from plugin module /etc/]
    

    我目前正在处理程序集插件,但我似乎在循环,没有任何工作。相当令人沮丧。如果您需要更多信息或不了解我的观点,请随时询问。-)

    另外要澄清我的问题:如何做到这一点?正如我之前所说,我对Maven的了解是有限的,目前我什么也得不到,即使我知道汇编插件可能是前进的道路。尤其是如何从每个模块获取依赖项,在哪里配置插件(在父项目中?)即使是一点汇编描述符也会有很大帮助。

    感谢您的所有意见!

    2 回复  |  直到 16 年前
        1
  •  1
  •   crowne    16 年前

    我使用程序集插件打包命令行应用程序的分发,如下所示:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-3</version>
        <configuration>
            <descriptors>
                <descriptor>src/main/assembly/bin.xml</descriptor>
            </descriptors>
        </configuration>
        <executions>
            <execution>
                <id>assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>assembly</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    
    • 定义程序集描述符,即指定可分发存档的内容和结构,我的定义如下:
    <assembly>
      <id>bin</id>
      <includeBaseDirectory>false</includeBaseDirectory>
      <formats>
          <format>zip</format>
      </formats>
      <fileSets>
          <fileSet>
              <directory>target</directory>
              <includes>
                  <include>ctmemapi.properties</include>
                  <include>ctmxml/*</include>
                  <include>scampa</include>
                  <include>*.bat</include>
                  <include>*.sh</include>
              </includes>
              <outputDirectory>${project.artifactId}-${project.version}</outputDirectory>
              <fileMode>755</fileMode>
          </fileSet>
          <fileSet>
              <directory>target</directory>
              <includes>
                  <include>scampa*.jar</include>
              </includes>
              <outputDirectory>${project.artifactId}-${project.version}/lib</outputDirectory>
              <fileMode>644</fileMode>
          </fileSet>
          <fileSet>
              <directory>src/test/data</directory>
              <outputDirectory>${project.artifactId}-${project.version}/test-data</outputDirectory>
              <fileMode>644</fileMode>
          </fileSet>
      </fileSets>
      <dependencySets>
          <dependencySet>
              <outputDirectory>${project.artifactId}-${project.version}/lib</outputDirectory>
              <fileMode>644</fileMode>
          </dependencySet>
      </dependencySets>
    </assembly>
    
    • 使用以下任一命令创建程序集

      MVN程序集:程序集
      打包
      根项目上进行构建
      MVN部署

        2
  •  0
  •   Pascal Thivent    16 年前

    如果您只是希望得到确认,那么我确认您所描述的情况是 Maven Assembly plugin . 我只需要使用单独的配置文件来处理限制(“ 只能向核心模块添加一个插件 “”。

    如果您希望得到更具体的指导,请添加一个具体的问题:)

    推荐文章