Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding additional resources to a Maven pom

I have a super pom defined in which I specify a "resources" directory for resources. In one of my projects, my pom extends that super pom, and I would like to add an additional resource. I tried:

    <resources>
        <resource>
            <targetPath>/</targetPath>
            <directory>additionalDir</directory>                
        </resource>
    </resources>

But that results in only additionalDir being in the resources and does not include the super pom's resources. Is there a way to extend the super pom's resources?

like image 414
Jeff Storey Avatar asked Jul 09 '09 01:07

Jeff Storey


People also ask

Where do you put resources in POM?

Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder. The lifecycle of Maven is not influenced by this. I have added resources successfully in . Jar file.


3 Answers

The behaviour you've described is expected.

Remember that your super POM is inheriting from Maven's default POM and pretty much any plugin that you define in your pom effectively overrides the setting in the default POM. As an example, to enable filtering on the default resource, you have to specify the path in your POM. You do this:

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>

Not this:

<resources>
  <resource>
    <filtering>true</filtering>
  </resource>
</resources>

The default directory does not bubble up for you, even if you've specified it there. There might be a special MOJO to do it for you, but I couldn't find one.

like image 120
Mike Cornell Avatar answered Oct 05 '22 14:10

Mike Cornell


See build-helper-maven-plugin's usage page.

like image 27
DanLebrero Avatar answered Oct 05 '22 14:10

DanLebrero


I know this question is pretty old by now but maybe someone will find this usefull:

You can easily do that using the maven resource plugin.

Basically, what it does by default (invoking the resources:resources goal) is moving the content of all directories listed in the build/resources section using the declared filter into the ${project.build.outputDirectory} If you now want to add some additional resources without influencing these sections, you can simply move the resources there yourself. An no, this does not mean drag and dropping it there.

The Maven Resources Pluginprovides a goal named resources:copy-resources that does exactly that for you: Coping files using filters from one place to another, or as the plugin doc states:

You can use the mojo copy-resources to copy resources which are not in the default maven layout or not declared in the build/resources element and attach it to a phase

The obvious advantage compared to the build-helper, that is suggested in other solutions, is that, while the build-helper is only able to take action during the generate-sources phase, the resources plugin works in any phase. (Though it would be wise to execute it before the packaging stage)

A full example on how to use this is provided here, as part of the plugins project page.

What this does is coping the content of the not listed resource directory "src/non-packaged-resources" into "${basedir}/target/extra-resources". But since the jar plugin (that creates the jar archive) basically creates a zip archive of the directory "${project.build.outputDirectory}", you may want to put it there.

like image 32
Omega1001 Avatar answered Oct 05 '22 14:10

Omega1001