Tuesday, March 24, 2020

pom.xml, profiles.xml and settings.xml

pom.xml, profiles.xml and settings.xml

Those are the three files which control lifecycle and settings of the Maven build process.

POM.XML

Clearly the most important file. It is an XML file which contains the essential information about a Maven project:
  • dependencies
  • plug-ins
  • goals to execute
In theory is the only mandatory file, however is good practice to store properties and settings externally (in the other files) and make the pom independent (or at least low coupled) with the specific developer’s environment.

PROFILES.XML

It enables the developer to define one or more profile descriptor. For example you could have an Oracle and a PostgreSQL profile:
<profiles>
  <profile>
    <id>oracle</id>
    <properties>
      <dbtarget>oracle</dbtarget>
      <db-url>jdbc:oracle:thin:@131.176.103.6:1521:mysid</db-url>
      <db-driver>oracle.jdbc.driver.OracleDriver</db-driver>
      <db-username>tiger</db-username>
      <db-password>scott</db-password>
      <sql-file>../sql/oracle/unittestdata.sql</sql-file>
    </properties>
  </profile>
  <profile>
    <id>postgresql</id>
    <properties>
      <dbtarget>postgresql</dbtarget>
      <db-url>jdbc:postgresql://localhost/test</db-url>
      <db-driver>org.postgresql.Driver</db-driver>
      <db-username>test</db-username>
      <db-password>test</db-password>
      <sql-file>../sql/postgresql/unittestdata.sql</sql-file>
    </properties>
  </profile>
</profiles>
Notice how properties are defined: just name the xml tag after the property, then this can be used within the pom (e.g. ${db-username}).

SETTINGS.XML

Settings.xml contains those attributes which are not bundled with the project therefore not distributed. Those could be specific profiles, repository location, etc..
Settings.xml can be placed in the {user.home}/m2 (on Windows C:\Documents and Settings\{user}\.m2)

No comments:

Post a Comment

String

  Java String  class provides a lot of methods to perform operations on strings such as compare(), concat(), equals(), split(), length(), re...