java 在构建 WAR 之前在 Maven 中重命名生成的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10230566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rename a generated file in Maven before building WAR
提问by John Farrelly
Fingers crossed you can help me!
手指交叉你可以帮助我!
I am using SmartSpritesto combine the PNGs on my landing page into one, so that it will load quicker.
我正在使用SmartSprites将着陆页上的 PNG 合并为一个,以便更快地加载。
SmartSprite will examine your CSS files, generate a CSS Sprite image, and create a new CSS file which will use this sprite image instead of the originals. What I want to do is replace the original CSS file with the SmartSprite one automatically during my maven WAR build.
SmartSprite 将检查您的 CSS 文件,生成一个 CSS Sprite 图像,并创建一个新的 CSS 文件,该文件将使用此 Sprite 图像而不是原始图像。我想要做的是在我的 maven WAR 构建期间用 SmartSprite 自动替换原始 CSS 文件。
So here's what I would like to happen:
所以这就是我想要发生的事情:
- SmartSprite scans my CSS file: mystyle.css
- SmartSprite create a sprite image, and creates a new mystyle-sprite.cssfile, which references the new sprite image.
- I want to copy mystyle-sprite.cssover mystyle.cssbefore the WAR is built, so that I don't have to change any of my references in the JSP files.
- SmartSprite 扫描我的 CSS 文件:mystyle.css
- SmartSprite 创建一个精灵图像,并创建一个新的mystyle-sprite.css文件,该文件引用新的精灵图像。
- 我想在构建WAR 之前将mystyle-sprite.css复制到 mystyle.css上,这样我就不必更改 JSP 文件中的任何引用。
Both files are located in the output directory (target/myproj/css). There doesn't seem to be any flag in SmartSprite to override the original file, so I guess it had to be done post-processing.
这两个文件都位于输出目录 (target/myproj/css) 中。SmartSprite 中似乎没有任何标志来覆盖原始文件,所以我想它必须进行后处理。
Below is the maven plugin configuration I'm using for 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>
采纳答案by Ates Goral
You can use the Maven WAR plugin:
您可以使用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>
You should also configure SmartSprites to use a different output directory to preserve the original CSS filename. Try the output-dir-path
option with an empty css-file-suffix
value.
您还应该将 SmartSprites 配置为使用不同的输出目录来保留原始 CSS 文件名。尝试output-dir-path
使用空css-file-suffix
值的选项。
回答by Micha? Kalinowski
I'm afraid you won't find anything simpler or more elegant than Maven AntRun Plugin with something like this:
恐怕你找不到比 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>