Tuesday, August 4, 2015

How to Use The Oracle Maven Repository

With the push of a lot of the 12c Series of products Oracle released it's own Maven repository. They made it functionally public a number of months ago, and I have been able to use it without incident since that time. Along with their release of the repository were instructions on how to use it here. The instructions however over explained in some areas and were a little convoluted in others. As a result I have decided to release a straight forward set of instructions.

Step 0: Maven Configurations
Of course I would say that it's going to be straight forward and then make things a little convoluted. As a matter of preference I like to keep my settings local to me rather than in the global settings file for maven that way between maven upgrades or in a shared environment I can bring my settings with me.

Global Maven Settings are stored in:
  Linux/Mac: $M2_HOME/conf/settings.xml
  Windows: %M2_HOME%\conf\settings.xml

Personal Settings are stored in:
  Linux/Mac: ~/.m2/settings.xml
  Windows: C:\Documents and Settings\<your-username>\.m2\settings.xml

If you want to start your own personal settings file the easiest way is to copy the it from the global. For the remainder of this tutorial I will assume you're working with Personal Settings

Step 1: Setup Maven Security
When connecting to authenticated Maven repositories you need to put your passwords into either your project POM file or into your settings.xml files. Either way your passwords and on your filesystem. To get this started first a master password needs to established and then your passwords in the future can be encrypted. Luckily Apache has a very simple article documenting these steps http://maven.apache.org/guides/mini/guide-encryption.html

Step 2: Configure Server
In the settings.xml add the following to the <servers> section:
    <server>
      <id>maven.oracle.com</id>
      <username>{USERNAME}</username>
      <password>{/ENCRYPTED_PASSWORD}</password>
      <configuration>
        <basicAuthScope>
          <host>ANY</host>
          <port>ANY</port>
          <realm>OAM 11g</realm>
        </basicAuthScope>
        <httpConfiguration>
          <all>
            <params>
              <property>
                <name>http.protocol.allow-circular-redirects</name>
                <value>%b,true</value>
              </property>
            </params>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
In place of the {USERNAME} should be your OTN email, and in place of {/ENCRYPTED_PASSWORD} should be the encrypted version of your password which you should now know how to generate from the Apache guide.

Step 3: Configure Profile
In the settings.xml add the following to the <profiles> section:
    <profile>
      <id>default</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>maven.oracle.com</id>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <url>https://maven.oracle.com</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>maven.oracle.com</id>
          <url>https://maven.oracle.com</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>

Step 5: Accept Terms and Conditions
With Oracle of course anything you want to download from them there is some sort of agreement, and the Maven Repository is not different. At lease with this one you only need to do it once. Go to https://www.oracle.com/webapps/maven/register/license.html and accept the terms.

Success
Provided that you followed all of these steps you should easily be able use oracle libraries as dependencies in your next project.

1 comment:

JAVAMAN said...

I try to connect to the MAVEN ORACLE REPOSITORY and made all these steps, but the error that i got was:

"Not authorized , ReasonPhrase:Unauthorized".