Typically, projects are deployed in multiple environments, each with its own resource configuration parameters, such as database connection, Redis server address, and so on. Therefore, the resources packaged by each environment are different. Manual modification takes time and effort. We can use MAVAN’s Profiles command to automate building different deployment packages.
Project resource configuration Generally, resource files referenced by a project can be divided into two types
Common resource files Different environment Resource files In the actual operation of the project, all referenced resource files are stored in the same resource directory, and stored according to different types. Therefore, when building the deployment package, use the maven-resources-plugin plugin and the profiles command to copy the differentiated resources of the target environment to the location of the common resources. You only need to copy the differentiated resource files of the target environment to the same directory as the common resources.
Configure profiles in POM.xml… dev <package.environment>dev</package.environment> true product <package.environment>product</package.environment> test <package.environment>test</package.environment> … In the Profiles node, three environments are defined: dev(the dev environment is enabled by default), test, and Product. You can add the required property values in your respective environment.
Create three folders (dev, test, product) to store various resources in different environments. The Maven standard directory provides a filters directory for storing resource filtering files.
SRC /main/filters/dev SRC /main/filters/test SRC /main/filters/product Avoid creating files in the Resources directory because files in the resources directory are not filtered by default. If the resources directory has been created for different environments in the old project, for example:
SRC/main/resources/dev SRC/main/resources/test/SRC/main/resources at this time of the product must be in pom. Configured in the XML node, is used to eliminate the environmental resource file. Thus, the SRC /main/resources directory contains only public resources. Note: If you Build a package using Maven in Eclipse, Build Automatically will be enabled by Eclipse. Automatically Build files from the Resources directory into the class output directory. Even configuring nodes in pom.xml to filter resources does not work. We don’t want the output deployment package to contain configurations that are not in the target environment (which could be leaked), so we recommend putting resource files for different environments in the Filters directory instead of the Resources directory.