eclipsemavenwarkeycloakeclipse-wtp

How to copy a resource from one maven project to another


i have a maven project consisting of a parent project with child projects. the children consist of many war projects and a single jar project (external). i want to copy a json file (keycloak.json) into the WEB-INF on all the war projects from a folder in the jar project.

so far i have it working by having a folder in every project containing all the keycloak.json. (a different keycloak.json is chosen depending on which maven profile is being used).

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven.war.plugin.version}</version>
    <configuration>
        <webResources>
            <resource>
                <directory>keycloak/${keycloak.dir}</directory>
                <targetPath>WEB-INF</targetPath>
                <filtering>true</filtering>
                <includes>
                    <include>**/keycloak.json</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

i am trying to move to getting the keycloak.json copied from the jar file so i don't have to duplicate it 20 times in the other projects. so far i have tried the below which seems to copy the file to target, but it is not picked up by WTP in eclipse

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copyKeycloak</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/WEB-INF</outputDirectory>
                <overwrite>true</overwrite>
                <resources>
                    <resource>
                        <directory>../external/src/main/resources/keycloak/${keycloak.dir}/</directory>
                        <includes>
                            <include>keycloak.json</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

Solution

  • in the end i found the solution which was much closer to my original. it depends on the relative project paths from the parent pom which is not a problem in my case. external is the name of my jar

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>${maven.war.plugin.version}</version>
        <configuration>
            <webResources>
                <resource>
                    <directory>../external/src/main/resources/keycloak/${keycloak.dir}</directory>
                    <targetPath>WEB-INF</targetPath>
                    <filtering>true</filtering>
                    <includes>
                        <include>**/keycloak.json</include>
                    </includes>
                </resource>
            </webResources>
        </configuration>
    </plugin>