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

时间:2012-04-19 14:42:33

标签: java maven css-sprites

手指越过你可以帮助我!

我正在使用SmartSprites将我的目标网页上的PNG合并为一个,以便加载更快。

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

所以这就是我想要发生的事情:

  1. SmartSprite扫描我的CSS文件: mystyle.css
  2. SmartSprite创建精灵图像,并创建一个新的 mystyle-sprite.css 文件,该文件引用新的精灵图像。
  3. 我想在构建WAR之前将 mystyle-sprite.css 复制到 mystyle.css ,这样我就不必更改任何我在JSP文件中的引用。
  4. 两个文件都位于输出目录(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>
    

2 个答案:

答案 0 :(得分:20)

我担心你找不到比Maven AntRun插件更简单或更优雅的东西:

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

答案 1 :(得分:2)

您可以使用Maven WAR plugin

<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文件名。尝试使用空output-dir-path值的css-file-suffix选项。