祈祷你能帮助我!
我正在使用 SmartSprites将我的着陆页上的 PNG 合并为一个,以便加载更快。
SmartSprite 将检查您的 CSS 文件,生成一个 CSS Sprite 图像,并创建一个新的 CSS 文件,该文件将使用该 sprite 图像而不是原始图像。我想要做的是在我的 Maven WAR 构建期间自动用 SmartSprite 文件替换原始 CSS 文件。
所以这是我希望发生的事情:
- SmartSprite 扫描我的 CSS 文件:mystyle.css
- SmartSprite 创建 Sprite 图像,并创建一个新的 mystyle-sprite.css 文件,该文件引用新的 Sprite 图像。
- 我想在构建 WAR 之前复制 mystyle-sprite.css 覆盖 mystyle.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 插件更简单或更优雅的东西了:
<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>
关于java - 在构建 WAR 之前在 Maven 中重命名生成的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10230566/