【问题标题】:Building arbitrary ditributions from Maven Project containing several and optional modules从包含多个可选模块的 Maven 项目构建任意分布
【发布时间】:2010-01-05 16:27:59
【问题描述】:

首先:我的 Maven 知识有限,请多多包涵。 ;-) 我有一个简单的 Maven 项目,目前由三个模块组成。包含应用程序核心的模块称为核心(创意名称,嗯?:-)),其他模块基本上是这个核心模块的插件。有一个限制:核心模块只能添加一个插件。

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

我想为负责部署系统的管理员提供一种简单的方法来构建包含核心、选定插件和合理默认配置的发行版。也许是tar.gz 或类似的东西。我不希望他挖掘我的 Spring IoC 文件,将它们复制在一起等等。诸如 TCP/IP 端口之类的实际配置是在属性文件中完成的。

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

/bin/core.jar [从核心模块构建] /bin/plugin.jar [从插件模块构建] /lib-bin/library-required-by-plugin.jar [maven + copy解决的依赖关系] /lib-bin/library-required-by-core.jar [maven + copy解决的依赖关系] /lib-bin/another-library-required-by-core.jar [依赖由 maven + 复制解决] /etc/spring/core-beans.xml [复制自核心模块 /etc/] /etc/spring/plugin.xml [从插件模块 /etc/ 复制] /etc/default-core-config.properties [从核心模块 /etc/ 复制] /etc/default-plugin-config.properties [从插件模块 /etc/ 复制]

我目前正在使用程序集插件,但我似乎在兜圈子,没有任何效果。相当令人沮丧。如果您需要更多信息或不明白我的意思,请随时询问。 :-)

另外澄清我的问题:如何做到这一点? (嗯,就是这么简单:-))正如我之前所说,我对 Maven 的了解是有限的,目前我无处可去,即使我知道汇编插件可能是要走的路。尤其是如何从每个模块中获取依赖关系,在哪里配置插件(在父项目中?),甚至是一些程序集描述符都会有很大帮助。

感谢您的所有意见!

【问题讨论】:

    标签: spring maven-2 distribution


    【解决方案1】:

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

    • 在 pom 中定义程序集插件,
      这包括将插件绑定到build life-cycle 的包阶段
    <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 包
      mvn 安装
      mvn 部署

    【讨论】:

    • 看起来很有希望,我会试试这个。
    • 感谢您的回答,它至少为我提供了一个粗略的起点。现在我必须找到一种将模块包含到程序集中的方法...如果有人为此提供了 sn-ps:欢迎您!
    • 您应该在 pom.xml 中将您的模块声明为依赖项。然后定义两个具有不同 outputDirectory 值的独立依赖集组,即 lib 和 lib-bin。将每个依赖集配置为仅包含您在该特定 outputDirectory 中需要的 jar。
    【解决方案2】:

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

    如果您期待更具体的指导,请添加具体问题:)

    【讨论】:

    • 添加了另一个带有实际问题的段落。我知道,这是非常通用的,因为我完全被卡住了,即使我现在什么也没有。到目前为止谢谢!
    猜你喜欢
    • 2014-03-03
    • 2014-05-22
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 2012-06-23
    • 2019-08-18
    • 2013-10-19
    相关资源
    最近更新 更多