sabato 2 aprile 2016

Maven & Oracle: "How To" & ""

In the last days a lot of developers/customers, has asked to me how to use maven during the development of projects with Oracle artifacts so I have decided to summarize here some solutions:

In this [POST] I have explained for example:
  1. How to use the local Maven Repository to push/get Oracle Jdbc drivers; The default path value is ${user.home}/.m2/repository/.
  2. Hot to use the remote Maven Repository on DevCS (Developer Cloud Service) to push/get Oracle Jdbc drivers
Now is time to introduce the (Oracle documentation)

Suppose that you are developing an application that requires and uses Oracle Jdbc Driver ojdbc7.jar, and that you would like to get it directly from internet from the remote Maven Repository

We need to write/update 2 files:
  1. pom.xml (inside your maven project)
  2. settings.xml
    • this file is inside the conf directoy of your maven installation.
    • can be also in  ${user.home}/.m2/) - Tools like Eclipse are searching it in this directory
To access to the Oracle Maven Repositoy - you need an user and a password, if you are already registered on OTNOracle Technology Network you can use the same user and password.

For the autentication we need to use HTTP Wagon, this is already inside Maven:

You must verify that the Maven that you are using has in his lib directory the wagon-http-shared-x.xx.jar and that the version (x.xx) is > 2.8

For examples I have installed Maven 3.3.9 and I'm using wagon-http-shared-2.10.jar.

If you are using an old version of Maven you cal download the HTTP Wagon (2.8) from [HERE] and put the jar in MAVEN_HOME/lib/ext/.

This is a sample of minimal pom.xml that you must use for example to get from the remote the ojdbc7.jar version

 <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">  

You must write also a settings.xml where you must insert your user and password:

edit your settings.xml that is inside the directory MAVEN_HOME/conf

  <!-- servers  
   | This is a list of authentication profiles, keyed by the server-id used within the system.  
   | Authentication profiles can be used whenever maven must make a connection to a remote server.  
     <realm>OAM 11g</realm>  

That's all :)

Now some Tips & Tricks:
  1. Setting a proxy in Maven
  2. Setting your Maven installation on Eclipse
  3. Browsing the remote
- [1] - If you are using a proxy update the pre-configured part <proxies>...</proxies> in the file settings.xml

- [2] - If you are working with Eclipse and you have also maven installed it is convenient to says to Eclipse to use your maven installation and not the embedded one. 

How to use from Eclipse an external maven installation:

I have created a simple maven project and I have dragged inside the previous described pom.xml file with the ojdbc7 dependency:

Righy click with the mouse on the pom.xml file and select: Run As-> Maven build ...
Choose a name (maven1 - package) and a Goal (package):
As you can see we are using the embedded Maven Runtime, click on Configure to change it:

Click the Add button:

Select the Directory where you have installed Maven on your local disk:
Click on Finish:

Check only the local maven installation:
Click on Apply then on OK:

Now your maven Runtime is changed, you can click on Run to execute the package goal:

In the console you can see that you are dowloading some files:

If you go in the ${user.home}/.m2/repository/ directory you can find what you have downloaded:

- [2] - How to browse the remote

I suggest to use: Nexus Repository OSS - I have downloaded and installed the version : (light, fast and simple)

Unzip it in a directory:

Go into the directory nexus-2.12.1-01:
Open a Command Console and execute "nexus console", this will start an http server on port 8081:

Open in a Broser the URL: http://localhost:8081/nexus

Login with the default user admin/admin123:

Click the Add button and select Add Proxy Repository:

Copy the following configuration (next 2 images) and insert your OTN User and Password:

Now you can browse the repository

You can also search on it, try to search ojdbc7:


2 commenti: