How to copy a resource or another in Maven depending on the target environment?

  • Use Maven profiles (http://maven.apache.org/guides/introduction/introduction-to-profiles.html)
  • Create a “dev” and “prod” profile, selecting an alternate set of resources for each profile. Make Dev active by default.

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources/dev</directory>
                    </resource>
                </resources>
            </build>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources/prod</directory>
                    </resource>
                </resources>
            </build>
        </profile>
    </profiles>
    
  • Build using the desired profile via:
    mvn install -Pdev
    or
    mvn install -Pprod

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)