Maven Combat (11) _ Upload widget to Nexus

Source: Internet
Author: User

A good build system must be flexible enough to allow projects to be built successfully in different environments. In order to support the flexibility of build, MAVEN has built in three major features: attribute, profile, and resource filtering .

1. Maven Properties

The Maven attribute is divided into 6 categories:
1, built-in properties: such as ${basedir} represents the project root directory, ${version} represents the project version
2, POM properties: The user can refer to the corresponding value in the Pom file. Such as:
${BASEDIR} Project root directory
${project.build.directory} build directory, default to target
${project.build.outputdirectory} build process output directory, default to Target/classes
${project.build.finalname} output name, default is ${project.artifactid}-${project.version}
${project.packaging} package type, default to Jar
${PROJECT.XXX} contents of any node of the current Pom file
3. Custom properties: The user can customize the MAVEN properties under the <properties> element of the Pom.
4. Setting property: The user can use a property beginning with settings to reference the value of an XML element in Settings.xml, such as ${settings.localrepository} to the address of the user's local warehouse.
5. Java System Properties: Maven can use the properties of the current Java system, such as ${user.home}, to point to the user directory.
6. Environment variable Properties: All environment variables can be used with Env. Properties that begin with. such as: ${env. Java_hoe}.

2. Resource filtering

Here the so-called resources: also refers to the src/main/resources and src/test/resources files under all the files, by default, these files will be copied to classpath below, that is, under the target/classes.
The so-called resource filtering is to filter the contents of the files under these folders to see if the MAVEN variable needs to be replaced. By default, only the variables inside the pom.xml are replaced, the resource files are not filtered, but can be set as follows:

[HTML]View Plaincopy print?
  1. <build>
  2. <finalname>agentmanager</finalname>
  3. <sourcedirectory>src/main/java</sourcedirectory>
  4. <resources>
  5. <!--control a copy of the resource file--
  6. <resource>
  7. <directory>src/main/resources</directory>
  8. <excludes>
  9. <exclude>**/jre.zip</exclude>
  10. <exclude>**/jre.tar</exclude>
  11. <exclude>agentmanager.jsmooth</exclude>
  12. <exclude>assembly.xml</exclude>
  13. </excludes>
  14. <targetpath>${project.build.directory}</targetpath>
  15. </Resource>
  16. <resource>
  17. <directory>src/main/resources/conf</directory>
  18. <targetpath>${basedir}/conf</targetpath>
  19. <filtering>true</filtering>
  20. </Resource>
  21. </Resources>
  22. </Build>


such as Jdbc.properties

[CSS]View Plaincopy print?
    1. Jdbc.driverclassname=${db.driver}
    2. Jdbc. url=${db. URL}
    3. Jdbc.username=${db.user}
    4. JDBC.PASSWORD=${DB.PWD}

Profile file

[HTML]View Plaincopy print?
  1. <profiles>
  2. <profile>
  3. <ID>dev</ID>
  4. <properties>
  5. <db.driver>oracle.jdbc.driver.oracledriver</db.driver>
  6. <db.url>jdbc:oracle:thin:@10.252.48.3:1521:dbname</db.url>
  7. <db.user>username</db.user>
  8. <db.pwd>userpwd</db.pwd>
  9. </Properties>
  10. </profile>
  11. <profile>
  12. <ID>test</ID>
  13. <properties>
  14. <db.driver>oracle.jdbc.driver.oracledriver</db.driver>
  15. <db.url>jdbc:oracle:thin:@10.252.48.3:1521:testdbname</db.url>
  16. <db.user>testusername</db.user>
  17. <db.pwd>testuserpwd</db.pwd>
  18. </Properties>
  19. </profile>
  20. </Profiles>



You can use the-p parameter to activate one or more profiles at build time, separated by commas
such as mvn clean Install-pdev

3. Maven Profile

The above example should be able to see what the profile is doing, in fact, it is equivalent to define a series of profiles, in the concrete construction can use one of them to replace the resource file.
There are many ways to activate profile, such as command line activation (above), settings file explicit activation, System attribute activation, operating system environment activation, default activation, file presence or not activation, etc., can refer to official website information .


Types of 3.1 profiles

Depending on your needs, you can declare profile in the following file.
1,Pom.xml for the current project
2. user settings.xml . M2/settings.xml in the user directory, valid for all items of the current user.
3. The global settings.xml is the Conf/settings.xml under the MAVEN installation directory. Valid for all items on this computer.

4. Web Resource filtering

In the MAVEN Web project, in addition to the above mentioned resource files (src/main/resources), there is a class called Web Resources directory, that is, Src/main/webapp below the JS, CSS and so on. By default, these directories are not filtered by resources, and the commands that are opened are as follows:

[HTML]View Plaincopy print?
  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactid>maven-war-plugin</artifactid>
  4. <version>2.1.1</version>
  5. <configuration>
  6. <webresources>
  7. <resource>
  8. <directory>src/main/webapp</directory>
  9. <filtering>true</filtering>
  10. <includes>
  11. <include>**/*.css</include>
  12. <include>**/*.js</include>
  13. </includes>
  14. </Resource>
  15. </webresources>
  16. </configuration>
  17. </plugin>

Maven Combat (11) _ Upload widget to Nexus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.