Question

I am minifying and aggregating my css files using the YUICompressor maven plugin which creates a single css file at the base of my resources directory. These original css files are nested inside some folders which also have an "images" folder at their same level.

I want to copy all the images that are in these nested image folders to be in one "images" folder at the base of my resources dir so that the aggregated css can still able to reference those images.

Here is my plugin configuration:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>copy-images-for-css</id>
            <!-- here the phase you need -->
            <phase>process-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>target/${project.artifactId}-${project.version}/plugin/resources/${plugin.client.version}/images</outputDirectory>
                <resources>
                    <resource>
                        <directory>target/${project.artifactId}-${project.version}/plugin/resources/${plugin.client.version}</directory>
                        <includes>
                            <include>**/images/*.*</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

For testing this out, I have put a .js file in the nested images file alongside the .gif and .jpg files I wish to copy over. However, only the .js file is moved to the correct place; nothing happens with the image files.

What gives?

UPDATE 1:

A more visual description of the directory structure:

resources
|--1.1.0
   |--all.min.css
   |--images          //a newly created folder
      |--sample1.gif   //the copied file
      |--sample2.gif   //the copied file
   |--category
      |--category.css
      |--images
         |--sample1.gif
   |--otherCategory
      |--otherCategory.css
      |--images
         |--sample2.gif

UPDATE 2: I just tried performing the copy with the copy-maven-plugin and had the same result, the js file is copied over but not the image files. Not sure if these plugins share functionality, but if not, it makes me think that there's something unrelated to the plugin going on. I am able to copy the files successfully using the windows command prompt.

Was it helpful?

Solution 2

I'm not sure on the timing of the copying of resources to the target dir, but it seems that the images simply weren't there in time for the copy. I realized that there was no real reason to need to copy from the target directory instead of my source. I updated the directory as shown below and the images were successfully copied over.

Before:

<directory>target/${project.artifactId}-${project.version}/plugin/resources/${plugin.client.version}</directory>

After:

<directory>src/main/webapp/plugin/resources/${plugin.client.version}</directory>

OTHER TIPS

Try to replace <include>**/images/*.*</include> with <include>**/images/*</include>. But it rather weird why it doesn't work with your variant. Also for your case it's better to use assembly plugin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top