在构建 WAR 之前重命名 Maven 中生成的文件



手指交叉你可以帮我!

我正在使用智能精灵将目标网页上的PNG合并为一个,以便加载速度更快。

SmartSprite 将检查您的 CSS 文件,生成一个 CSS 精灵图像,并创建一个新的 CSS 文件,该文件将使用此精灵图像而不是原始图像。 我想做的是在我的maven WAR构建期间自动将原始CSS文件替换为SmartSprite文件。

所以这就是我希望发生的事情:

  1. SmartSprite 扫描我的 CSS 文件:mystyle.css
  2. SmartSprite 创建一个精灵图像,
  3. 并创建一个新的 mystyle-sprite.css 文件,该文件引用新的精灵图像。
  4. 我想在构建 WAR 之前.css mystyle 复制 mystyle-sprite.css这样我就不必更改 JSP 文件中的任何引用。

这两个文件都位于输出目录(target/myproj/css)中。 SmartSprite 中似乎没有任何标志可以覆盖原始文件,所以我想它必须进行后期处理。

下面是我用于SmartSprite的maven插件配置。

        <plugin>
            <groupId>org.carrot2.labs</groupId>
            <artifactId>smartsprites-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>spritify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

怕你找不到比Maven AntRun Plugin更简单或更优雅的东西了:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.7</version>
      <executions>
        <execution>
          <phase>prepare-package</phase>
          <configuration>
            <target>
              <copy file="${project.build.directory}/mystyle-sprite.css"
                tofile="${project.build.directory}/mystyle.css" />
            </target>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

您可以使用Maven WAR插件:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <directory><!-- Your output directory --></directory>
                <targetPath><!-- The target location of the files below --></targetPath>
                <includes>
                    <include><!-- file pattern --></include>
                    <include><!-- file pattern --></include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

您还应该将 SmartSprites 配置为使用不同的输出目录来保留原始 CSS 文件名。尝试使用空css-file-suffix值的output-dir-path选项。

最新更新