How to set a profile for your Web program (War package)
Conventions
Http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
The link above says:
The default resource directory for all Maven projects is src/main/resources which'll end up in target/classes and in WEB -inf/classes in the WAR. The directory structure is preserved in the process.
The WAR Plugin is also capable of including resources not found in the default resource directory through the WebResources Parameter.
The default is to find the Src/main/resource directory configuration as the war package configuration, if not found, you can use the user-defined, as follows, the user defined directory Resource2 as a custom directory.
<project> ... <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid > <artifactId>maven-war-plugin</artifactId> <version>2.4</version> < configuration> <webResources> <resource> <!--This was relative to the Pom.xml Directory-- <directory>resource2</directory> </resource> </ webresources> </configuration> </plugin> </plugins> </build> ...</project>
For example, if your project directory is as follows:
. |--pom.xml |--Resource2 | | --External-resource.jpg | '--image2 | '--external-resource2.jpg '--src '--main |--java | '--com | '--Example | '--Projects | '--Sampleaction.java |--Resources | '--Images | '--sampleimage.jpg '--webapp |--web-inf | '--web. |--index.jsp '-- JSP '--websource.jsp
Then, after executing the above Pom, the war package content should look like this:
Documentedproject-1.0-snapshot.war |--Meta-inf | | --MANIFEST. MF | '--maven | '--com.example.projects | '--documentedproject | | --Pom.properties | '--pom.xml |--Web-inf | | --Classes | | | --com | | | '--Example | | | '--projects | | | '--sampleaction.class | | '--Images | | '--sampleimage.jpg | '--web. XML |--external-resource.jpg |--image2 | '--external-resource2.jpg |--index.jsp '--JSP '--websource.jsp
As you can see, this war package has not only the configuration under the Src/main/resource directory, but also the configuration under Resource2.
Description, the war configuration, from two places, one is the default, one is added by the user.
How to overwrite?
Our most common user scenarios are:
All configurations developed under the Src/main/resource directory
The Src/main/online-resource directory is configured on the wire. It does not contain all configurations. It contains only the configuration files in the Src/main/resource directory that need to be replaced with a line configuration. That is, the development and the online configuration of the common configuration file will not exist in this directory.
So, our idea is simple, the configuration of the online war should include:
- First, all files in the Src/main/resource directory should be included
- Then, using the Src/main/online-resource overlay above this directory, the offline configuration is covered in line configuration, the common configuration is preserved.
How do you do all of these things?
Https://github.com/knightliao/disconf/blob/master/disconf-web/pom.xml provides a best practice here:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId> maven-war-plugin</artifactid> <configuration> <webResources> <resource> <directory>${project.build.online.sourceDir}</directory> <targetpath>web-inf/ classes</targetpath> <includes> <include>**/*.*</include> </includes > </resource> </webResources> </configuration></plugin>
Just like the above configuration, MAVEN helps us to do the first step by default (first, should include all the files in the Src/main/resource directory), we have customized the second step, MAVEN will help us to cover out.
Maven War Package pom configuration file