开发者

Building arbitrary ditributions from Maven Project containing several and optional modules

first of all: my Maven knowledge is limited so please bear with me. ;-) I have a simple Maven Project currently consisting of three modules. The module containing the core of the application is called core (Creative name, huh? :-)) and the other modules are basically plugins for this core module. There is one restriction: Only one plugin can be added to the core module.

The core module has its own Spring IoC configuration minus the plugin configuration. This is quite simple: The core code will read a bean named "plugin" which is not defined in the core configuration. The plugin modules will ship their own configuration files which will supply a bean named "plugin" which is then used by the core code. This fits perfectly in my use-case.

I want to provide the Admin, which will deploy the system, a simple way to build a distribution containing t开发者_StackOverflowhe core, a selected plugin and a reasonable default configuration. Maybe a tar.gz or something like that. I don't want him to dig though my Spring IoC files, copy them together, etc. etc. The actual configuration like TCP/IP ports are done in property files.

To clarify what i mean I've build an example structure. Note that the filenames are for explanation purposes only.

/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/]

I currently mess around with the assembly plugin but i seem to go round in circles and nothing works. Pretty frustrating. If you need any more information or do not get my point feel free to ask. :-)

Addition to clarify my question: How to do that? (Well, its just that simple :-)) As I stated before, my knowledge of Maven is limited and currently i'm getting nowhere, even if I know that the assembly plugin might be the way to go. Especially how to get the dependencies from each module, where to configure the plugin (In the parent project?) and even a bit of an assembly descriptor would help a lot.

Thank you for all your input!


I used the assembly plugin to package a distribution of a command line application as follows:

  • Define assembly plugin in pom,
    this includes binding the plugin to the package phase of the 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>
  • Define the assembly descriptor, i.e. specify the contents and structure of your distributable archive, here's mine below:
<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>
  • Create the assembly with either of the following commands

    mvn assembly:assembly
    mvn package
    mvn install
    mvn deploy


If you are just expecting a confirmation, then I confirm that the situation you have described is a perfect use case for the Maven Assembly plugin. I'd just use separate profiles to deal with the restriction ("Only one plugin can be added to the core module").

If you are expecting more specific guidance, please add a specific question :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜