views:

905

answers:

2

I'm trying to get Maven to assemble a WAR with the BIRT runtime in a useful location within the WAR.

The BIRT runtime is in the pom.xml as

<dependency>
  <groupId>org.eclipse.birt</groupId>
  <artifactId>report-engine</artifactId>
  <version>2.3.2</version>
  <type>zip</type>
  <scope>runtime</scope>
</dependency>

The desired outcome of overlaying this is something like

ReportEngine/lib/*           -> WEB-INF/lib 
ReportEngine/configuration/* -> WEB-INF/platform/configuration 
ReportEngine/plugins/*       -> WEB-INF/platform/plugins

My overlay configuration looks like

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <overlays>
      <overlay>
        <groupId>org.eclipse.birt</groupId>
        <artifactId>report-engine</artifactId>
        <type>zip</type>
        <includes>
          <include>ReportEngine/lib/*</include>
        </includes>
        <targetPath>WEB-INF/lib</targetPath>
      </overlay>
      <overlay>
        <groupId>org.eclipse.birt</groupId>
        <artifactId>report-engine</artifactId>
        <type>zip</type>
        <includes>
          <include>ReportEngine/configuration/*</include>
          <include>ReportEngine/plugins/*</include>
        </includes>
        <targetPath>WEB-INF/platform</targetPath>
      </overlay>
    </overlays>
  </configuration>
</plugin>

Of course, when running mvn war:exploded I'm seeing

ReportEngine/lib/*           -> WEB-INF/lib/ReportEngine/lib/ 
ReportEngine/configuration/* -> WEB-INF/platform/configuration/ReportEngine/lib/ 
ReportEngine/plugins/*       -> WEB-INF/platform/plugins/ReportEngine/lib/

This relates, same sort of problem, no answer http://www.coderanch.com/t/447258/Ant-Maven-Other-Build-Tools/Maven-war-dependencies-moving-files

Bonus points for pointing out how I can tidy this up a bit by having it all work from within WEB-INF/birt-runtime

Edit:

The reason for the locations specified above are that they match those indicated in http://wiki.eclipse.org/Servlet_Example_%28BIRT%29_2.1 and when I fritz with the Tomcat installation to mimic this, it all seems to work. It would be ideal if I could simply overlay the zip into WEB-INF/birt-runtime and then set the engine config appropriately, but I've not found that to work as yet.

Eg:

engineConfig = new EngineConfig();
engineConfig.setEngineHome("WEB-INF/birt-runtime");
engineConfig.setPlatformContext(new PlatformServletContext(servletContext));
A: 

Update: On rereading the question I realise I missed out the sub-directories from my test project, so of course it worked for me, sorry for that.

As far as I know there exists no mechanism in either the war overlay or the dependency-plugin to unpack sub-folders of artifacts to a directory and exclude the parent elements of the path, both are going to give you the full relative path.

You can however use the unpack goal to unpack the archive to a temporary folder, then use the antrun-plugin to copy the required subfolders to their final resting places.

The following configuration would do just that (I've not yet tested this so apologies if there are any omissions, see the documentation for exact details). Note the executions are in the same phase, but as long as the dependency-plugin is configured before the antrun-plugin it would be executed first. Note, the prepare-package is new for Maven 2.1, if you're on an older version you'd need to use another phase.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>unpack-lib</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>unpack</goal>
      </goals>
      <configuration>
        <artifactItems>
          <artifactItem>
            <groupId>org.eclipse.birt</groupId>
            <artifactId>report-engine</artifactId>
            <version>2.3.2</version>
            <type>jar</type>
            <overWrite>false</overWrite>
          </artifactItem>
        </artifactItems>
        <!--unpack all three folders to the temporary location-->
        <includes>ReportEngine/lib/*,ReportEngine/configuration/*,ReportEngine/plugins/*</includes>
        <outputDirectory>${project.build.directory}/temp-unpack</outputDirectory>
        <overWriteReleases>false</overWriteReleases>
      </configuration>
    </execution>
  </executions>
</plugin>
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>prepare-package</phase>
        <configuration>
          <tasks>
            <!--now copy the configuration and plugin sub-folders to WEB-INf/platform-->
            <copy todir="${project.build.directory}/WEB-INF/platform">
              <fileset dir="${project.build.directory}/temp-unpack/ReportEngine/configuration"/>
              <fileset dir="${project.build.directory}/temp-unpack/ReportEngine/plugins"/>
            </copy>
            <!--copy the lib sub-folder to WEB-INf/lib-->
            <copy todir="${project.build.directory}/WEB-INF/lib">
              <fileset dir="${project.build.directory}/temp-unpack/ReportEngine/lib"/>
            </copy>
          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
Rich Seller
OK< if it worked for you I'll need to see why I can't get it going this end.
ptomli
A bit of mucking about and this is now working :) ThanksI had to use generate-resources phase as I'm running 2.0.9, and there's some issues integrating with m2eclipse (https://issues.sonatype.org/browse/MNGECLIPSE-1304). Another day I'll see about convincing m2eclipse/WTP to use the files in a metadata Tomcat published scenario.
ptomli
A: 

Not really answering my own question, responding to Rich Seller above :)

Trying to get this to work with mvn dependency:unpack, the docs say to take it out of the executions node. Not sure if that is the cause of the result, but this ends up with

WEB-INF/lib/ReportEngine/lib
WEB-INF/platform/ReportEngine/configuration
WEB-INF/platform/ReportEngine/plugins

basically the same as my initial war-plugin attempt. I don't see anything in the docs for depedency-unpack to assist. I'll try again tmrw.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>

      <configuration>
        <artifactItems>
          <artifactItem>
            <groupId>org.eclipse.birt</groupId>
            <artifactId>report-engine</artifactId>
            <version>2.3.2</version>
            <type>zip</type>
            <overWrite>false</overWrite>
            <!--may not be needed, need to check-->
            <outputDirectory>${project.build.directory}/WEB-INF/lib</outputDirectory>
            <includes>ReportEngine/lib/*</includes>
          </artifactItem>

          <artifactItem>
            <groupId>org.eclipse.birt</groupId>
            <artifactId>report-engine</artifactId>
            <version>2.3.2</version>
            <type>zip</type>
            <overWrite>false</overWrite>
            <!--may not be needed, need to check-->
            <outputDirectory>${project.build.directory}/WEB-INF/platform</outputDirectory>
            <includes>ReportEngine/configuration/*,ReportEngine/plugins/*</includes>
          </artifactItem>
        </artifactItems>
      </configuration>
</plugin>
ptomli
You can edit your question with these details rather than putting them in an answer. I've updated my answer t hopefully actually address your problem. Sorry for misreading the question and wasting your time.
Rich Seller