Integrate Oracle JDBC driver, UCP Pool, ONS and JSF with Maven

Add Oracle JDBC driver in your Maven local repository

[oracle@wls1 Driver]$ mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7 \
 -Dversion=12.1.0.2 -Dpackaging=jar -Dfile=ojdbc7.jar -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /home/oracle/JDBC/Driver/ojdbc7.jar to /home/oracle/.m2/repository/com/oracle/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.jar
[INFO] Installing /tmp/mvninstall5544900966056750978.pom to /home/oracle/.m2/repository/com/oracle/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.552s
[INFO] Finished at: Wed Apr 15 08:45:56 CEST 2015
[INFO] Final Memory: 5M/42M
[INFO] ------------------------------------------------------------------------

 
Create a new Netbeans project -> Maven -> Web Application 
  Add            : Wildfly Server & JEE7 support 
  Add JSF Support:  Properties -> Framework -> Add -> JavaServer Faces 

This will create index.xhtml under Web Pages directory. Change it to  
    <h:body>
        Hello from Maven JSF and JDBC test
    </h:body>
Run it and verify that above string was printed 
  http://localhost:8180/WFMavenJDBC-1.0-SNAPSHOT/


Note As our JDBC driver is installed as a module add: <scope>runtime</scope>
pom.xml: 
   <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc7</artifactId>
      <version>12.1.0.2</version>
      <scope>runtime</scope>
    </dependency>
  
runtime:
This scope indicates that the dependency is not required for compilation, but is for execution. 
It is in the runtime and test classpaths, but not the compile classpath.
Note  <scope>runtime</scope> does not work 

For Details how to install Oracle JDBC driver please read following article: 
How to integrate the Oracle JDBC driver as a Wildfly module ?

Integrate ONS and UCP in your local Maven repository

[oracle@wls1 lib]$ pwd
/home/oracle/UCP/lib
[oracle@wls1 lib]$ ls
ojdbc7.jar  ons.jar  ucp.jar
[oracle@wls1 lib]$ mvn install:install-file -DgroupId=com.oracle -DartifactId=ucp \
  -Dversion=12.1.0.2 -Dpackaging=jar -Dfile=ucp.jar -DgeneratePom=true
[INFO] Scanning for projects...
--------------------------------------------------------------------
...
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /home/oracle/UCP/lib/ucp.jar to /home/oracle/.m2/repository/com/oracle/ucp/12.1.0.2/ucp-12.1.0.2.jar
[INFO] Installing /tmp/mvninstall8385397296650809803.pom to /home/oracle/.m2/repository/com/oracle/ucp/12.1.0.2/ucp-12.1.0.2.pom
Add to pom.xml in your Maven project: 
   <dependency>
     <groupId>com.oracle</groupId>
     <artifactId>ucp</artifactId>
     <version>12.1.0.2</version>
   </dependency> 

[oracle@wls1 lib]$ mvn install:install-file -DgroupId=com.oracle -DartifactId=ons \
  -Dversion=12.1.0.2 -Dpackaging=jar -Dfile=ons.jar -DgeneratePom=true
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /home/oracle/UCP/lib/ons.jar to /home/oracle/.m2/repository/com/oracle/ons/12.1.0.2/ons-12.1.0.2.jar
[INFO] Installing /tmp/mvninstall1244421194501868057.pom to /home/oracle/.m2/repository/com/oracle/ons/12.1.0.2/ons-12.1.0.2.pom

Add to pom.xml in your Maven project: 
   <dependency>
     <groupId>com.oracle</groupId>
     <artifactId>ons</artifactId>
     <version>12.1.0.2</version>
   </dependency> 

Manually compile and deploy the WAR file

[oracle@wls1 Desktop]$ cd  /home/oracle/NetBeansProjects/GIT/WFMavenJDBC
[oretacle@wls1 WFMavenJDBC]$ ls *.xml
nb-configuration.xml  pom.xml  
[oracle@wls1 WFMavenJDBC]$ mvn clean
[oracle@wls1 WFMavenJDBC]$ mvn package
[oracle@wls1 WFMavenJDBC]$ $WILDFLY_HOME/bin/jboss-cli.sh --connect --command="deploy --force target/WFMavenJDBC-1.0-SNAPSHOT.war"
[oracle@wls1 WFMavenJDBC]$ firefox http://localhost:8180/WFMavenJDBC-1.0-SNAPSHOT/

Testing the application

 
Invoke:  CheckJDBC
  JDBC Driver Check - Loading Driver class ok : oracle.jdbc.OracleDriver
  JDK Version: 1.7.0_71
  ClassPath  : /usr/local/wildfly-8.2.0.Final/jboss-modules.jar
  Driver Name             : Oracle JDBC driver
  Driver Version          : 12.1.0.2.0
  Database Product Version: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Advanced Analytics and Real Application Testing options

Invoke: IinitUCP
  Initializing UCP Pool in progress ...
  UCP Pool initialized !
  RAC DB: BANKA
  Instance Name:bankA_2 - Host: hract22.example.com
  Instance Name:bankA_3 - Host: hract21.example.com
  Instance Name:bankA_2 - Session Count 10
  Instance Name:bankA_3 - Session Count 9

 

Source and Configuration Files

Reference

Leave a Reply

Your email address will not be published. Required fields are marked *