在构建WAR之前在Maven中重命名生成的文件
手指交叉可以帮助我!在构建WAR之前在Maven中重命名生成的文件
我正在使用SmartSprites将我的着陆页上的PNG合并为一个,以便加载速度更快。
SmartSprite将检查您的CSS文件,生成CSS Sprite图像,并创建一个新的CSS文件,该文件将使用此精灵图像而不是原件。我想在我的maven WAR版本中自动替换原始CSS文件和SmartSprite。
因此,这里是我想发生什么:
- SmartSprite扫描我的CSS文件:mystyle.css
- SmartSprite创建一个精灵的形象,并创建一个新myStyle的-sprite.css文件,它引用了新的精灵图像。
- 我要复制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 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。尝试使用空值css-file-suffix
值output-dir-path
选项。
恐怕你不会找到任何简单的或比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>
也许你应该移动文件而不是复制。您不希望在最终的WAR中留下构建工件。 – 2012-04-19 15:01:39
没问题。将'
关于重命名文件而不使用程序集,这应该是被接受的答案 - 只保存我的一天:-) – Gunnar 2015-12-16 14:05:40
嗨阿泰,我将如何重新命名myStyle的-sprite.css文件为myStyle的.css使用资源?我认为只能包含或排除文件,但在传输过程中不能更改其名称。 – 2012-04-19 14:54:20
@JohnFarrelly更新了我的答案。尝试使用不同的输出目录(与WAR的默认暂存区域不同)。 – 2012-04-19 14:56:01
而且,哦,是的,这将工作。我使用这种方法稍微不同的方案(RequireJS优化JS + CSS文件)。 – 2012-04-19 14:58:56