Rename the generated file to Maven before creating the WAR

Fingers crossed, you can help me!

I use SmartSprites to combine the PNGs on my landing page into one so that it loads faster.

SmartSprite will check your CSS files, generate a Sprite CSS image, and create a new CSS file that will use this sprite image instead of the originals. What I want to do is replace the SmartSprite CSS source file automatically during build of my maven WAR.

So here is what I would like to do:

  • SmartSprite scans my CSS file: mystyle.css
  • SmartSprite creates a sprite image and creates a new mystyle-sprite.css file that references the new sprite image.
  • I want to copy mystyle-sprite.css on top of mystyle.css before creating a WAR, so I don’t need to change any of my links in JSP files.

Both files are in the output directory (target / myproj / css). There is no flag in SmartSprite to override the original file, so I assume that it should have been done after processing.

The following is the maven plugin configuration that I use for SmartSprite.

        <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>
+3
source share
2 answers

You can use the 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>

You must also configure SmartSprites to use a different output directory to preserve the original CSS file name. Try a parameter output-dir-pathwith an empty value css-file-suffix.

+2
source

, , 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>
+18

All Articles