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)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: