开发者

maven: add arbitrary file as a servlet context resource

I have a maven war p开发者_如何转开发roject 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).


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜