Monday Jul 29, 2013

JDeveloper 12c and Maven: Using relative paths in your POM files

One of the greatest things about JDeveloper 12c is the significantly improved support for Apache Maven. By default, the POM files produced by my favorite IDE contain some absolute paths, such as the folder for the ojmake/ojdeploy executables and references to project (.jpr) and application (.jws) files. Here is a sample of such paths extracted from an application I created on a Windows machine.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
      <plugin>
        <groupId>com.oracle.adf.plugin</groupId>
        <artifactId>ojmake</artifactId>
        <version>12.1.2-0-0</version>
        <configuration>
          <ojmake>
            C:\Oracle\Middleware1212\jdeveloper\jdev\bin\ojmake.exe
          </ojmake>
          <files>
            C:\OracleData\JDEV_USER_DIR\mywork\MavenTest\Model\Model.jpr
          </files>
          <usemaven>
            true
          </usemaven>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

This is perfectly fine if your development team uses workstations that are configured in a consistent way and run under the same operating system. It is often not the case in the real world. Fortunately, Maven provides features that make it very easy to use relative paths instead.

The first thing you should know is that Maven supports the use of variables in POM files. Those variables are always referenced using the following syntax:

${variable_name}

There are several built-in variables provided by Maven. One of them is ${basedir}, which points to the folder where the current POM is located. In addition, Maven can access any environment variable defined by the operating system. This is achieved though the following syntax:

${env.variable_name}

 Thus, it is possible to remove all absolute paths from the sample above by using ${basedir} and referencing an environment variable. Suppose I created such a variable named OJ_HOME, which points to  C:\Oracle\Middleware1212\jdeveloper\jdev\bin. Then, the POM would look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
      <plugin>
        <groupId>com.oracle.adf.plugin</groupId>
        <artifactId>ojmake</artifactId>
        <version>12.1.2-0-0</version>
        <configuration>
          <ojmake>
            ${env.OJ_HOME}\ojmake.exe
          </ojmake>
          <files>
            ${basedir}\ViewController.jpr
          </files>
          <usemaven>
            true
          </usemaven>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

This POM will run on any workstation, granted the OJ_HOME variable is set to a suitable value.

About

Frédéric Desbiens

The musings of a member of the ADF Product Management team.

I focus here on my favorite development framework but also have a strong interest in Mobile Development, Oracle WebCenter and Oracle SOA Suite.

Attentive readers will even find posts about IT Strategy from time to time, an interest of mine since I completed my MBA in 2006.

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today