views:

55

answers:

1

I have a maven war project which produces webapp.war, and a maven 'skin' project which produces skin.zip (a file full of resources and XML files). Now I want to add this zip file as a servlet context resource (e.g WEB-INF/skin.zip).

I tried using overlays, but it expands the zip file into WEB-INF instead of placing the un-expanded file there:

    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <overlays>
                <overlay>
                    <groupId>com.mycompany</groupId>
                    <artifactId>skin</artifactId>

                    <type>zip</type>
                    <targetPath>WEB-INF</targetPath>
                </overlay>
            </overlays>
        </configuration>
    </plugin>

Is there any way to prevent it from expanding the resource -- or somehow stick the file in there (without using ant-plugin).

Note: type is a totally unnecessary and unhelpful configuration element -- it does not tell the plugin how to expand the artifact, as you might expect -- it tells it how to FIND it. For example if you change type from zip to jar, it complains that it can't find the artifact (in the most unhelpful way possible).

+1  A: 

I tried using overlays, but it expands the zip file into WEB-INF

Yes, that's what overlays do, the content is unpacked to be merged with the war. That's just not the right tool in your case.

Is there any way to prevent it from expanding the resource -- or somehow stick the file in there

I would use the Maven Dependency Plugin and its dependency:copy goal:

  • dependency:copy takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in local.

And bind it on the prepare-package phase. Below, some starting point:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-prepare-package</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.mycompany</groupId><!-- or ${project.groupId} -->
                  <artifactId>skin</artifactId>
                  <version>X.Y.Z</version><!-- or ${project.version} -->
                  <type>zip</type>
                </artifactItem>
              </artifactItems>
              <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

See Copying specific artifacts for more examples.

Pascal Thivent
This works, although the down side of it being copied rather than included as an overlay; is that any current/future overlay-aware IDE plugins (i'm thinking m2eclipse) won't _know_ about the dependency as being a component of a war file -- and thus you get separate deploytime vs. IDE debug/run-time behavior.
Justin
@Justin Ah, I see. I'm afraid the alternative would be to include your skin.zip **in** another archive to get overlays working. That's possible though.
Pascal Thivent