Java and JDBC for Oracle DBAs – Part 2: Java, Eclipse, Maven & JDBC

Today I’ll continue with my series on creating an Java and JDBC test application for Oracle DBAs.

Part 2: Installing Java, Eclipse and Maven

First of all, if you want to develop in Java, you’ll need the Java Development Kit (JDK). In this blog we’ll be using Java version 8.

Then there are different Java GUI developer tools to choose among. The two most popular ones are IntelliJ and Eclipse. IntelliJ have a community edition which can be used for free (Download from https://www.jetbrains.com/idea/download).

In this blog I choose to use Eclipse (see picture on the left), but I regularly use IntelliJ in different projects. Eclipse is free, and can be downloaded from https://www.eclipse.org/ (but see the section below for specific versions). To keep it simple, I’ll only refer to Eclipse in these tutorials, but you can probably manage if you choose IntelliJ too.

When working with Java you often use different API’s which is already written and available. Handling dependencies between different JARs (packaged Java libraries) can be a difficult job. In addition, an application needs to go through different steps in the development project. These steps could be downloading jars, compiling, building, packaging, testing, deployment and finally running the code. This could be rather tedious, and Java developers usually choose to use tools like Ant, Maven or Gradle to handle such tasks. In this blog I’ll be using Maven.

Installing the Java Development Kit (JDK)

The Java Development Kit is the foundation of your Java development. The Java software (together with the Solaris operating system) were the main reasons why Oracle bought Sun in 2009. For this reason you’ll find the Java JDK downloads on Oracle’s webpages.

Download

In this blog series I’ll be using the Java SE Development Kit 8u172 found at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. Scroll down to the 172 release, check the “Accept License Agreement” and download the file for you operating system and processor (32bits or 64-bits). For Linux you can choose among an rpm file or tar.gz file. I always prefer to use the simple packaged and compressed tar.gz file.

Installing the Java Development Kit

For Windows and Mac the installation is rather straight forward. Run the installation file (.dmg for Mac or .exe for Windows), and follow the instructions. For Linux (using the tar.zip file) untar the files where you want your Java installation. If you want to install your JDK into a system-wide location such as /usr/jdk or /opt/java, you must first become root to gain the necessary privileges.

If needed you can find the installation documentation for you environment at:

Example from Max (OS X) installation

Verify your JDK installation

To verify you installation run the following command in a console:

$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
$ javac -version
javac 1.8.0_172

If the java or javac binaries are not found then you need to add the directory path to the binaries.
For instance in Linux:

$ export PATH=/opt/java/jdk-1.8.0_172/bin:$PATH
$ export JAVA_HOME=/opt/java/jdk-1.8.0_172

Installing a development GUI: Eclipse Oxygen 3A

Download

The Eclipse installation files can be downloaded from www.eclipse.org. The naming of eclipse versions can feel a little strange, but it’s just another way to recognize a new version of the software. The latest release “Eclipse Phantom” (released June 2018) is really version 4.8. The version before this (version 4,7, released June 2017) is named “Eclipse Oxygen”. We’ll use an extended version called “Eclipse Oxygen 3A” found at https://www.eclipse.org/downloads/packages/release/Oxygen/3A. I think you could choose between “Eclipse IDE for Java EE Developers” or “Eclipse IDE for Java Developers”, but to be sure go for the Java EE version (which I’ll be using). Then you choose the installation file for your operating system, and if you want 32-bits or 64-bit version. I’ll be using the 64-bit version (since this is the only one for Mac).

Installing Eclipse IDE for Java EE Developers (version Oxygen, 3A)

After downloading the correct file, the installation should be rather straight forward. For Mac the downloaded file will be a regular installation file (.dmg). For Windows and Linux this will be a .zip file (windows) and a .tar.gz file (Linux). Extract the zip or tar file, and run the packaged installer.

Installing Maven

Download and configure

In this blog series we’ll be using Maven version 3.5.4 which can be downloaded from https://archive.apache.org/dist/maven/maven-3/3.5.4/binaries/. Download the file “apache-maven-3.5.4-bin.tar.gz”, and untar in an appropriate location:

$ cd /Users/lassejenssen/Downloads
$ mv apache-maven-3.5.4-bin.tar.gz /Users/lassejenssen/Applications
$ tar -xzvf apache-maven-3.5.4-bin.tar.gz
$ rm apache-maven-3.5.4-bin.tar.gz

Update your PATH environmentvariable. The method of doing this will depend on your operating system.

$ export PATH=/Users/lassejenssen/Applications/apache-maven-3.5.4/bin:$PATH

To test your maven setup, run the following:

$ mvn -version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T19:33:14+01:00)
Maven home: /Users/lassejenssen/Applications/apache-maven-3.5.4
Java version: 1.8.0_172, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.5", arch: "x86_64", family: "mac"

Installing the Oracle JDBC drivers with Maven

Normally maven would take care of downloading the library dependencies which we configure in the maven configuration file (pom.xml). Note! We’ll look further at the pom.xml in part 3 of this blog series. The Oracle JDBC drivers is protected by the Oracle licensing rules (as all of the Oracle software), and need some special attention. When it comes to the Oracle JDBC driver files we have to options: 1) Download the files from Oracle’s download pages and install these manually into the local maven repository 2) Configure maven to authenticate with your support account towards the Oracle Maven repository. We’ll use the first method which is described below, but I have also included a link to a description of alternative 2 (see below).

Alternative 1: Download the files from Oracle’s download pages

Download the Oracle JDBC drivers

We will be using the Oracle 12c Release 2 (version 12.2.0.1) JDBC files. Download the files “ojdbc8.jar” and “ucp.jar” from the Oracle download pages: https://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html. We’ll be talking more about these files later, but the ucp.jar includes classes for the Universial Connection Pool for use with JDK 8 (which we have installed earlier in this blog).

Manually install the Oracle JDBC drivers into the local maven repository

Maven stores the downloaded Java libraries in a local repository. The repository directory “.m2” is located default in your $HOME directory. Run the following commands to manually install the downloaded JDBC drivers into the local repository:

$ mvn install:install-file -Dfile=/Users/lassejenssen/Downloads/ojdbc8.jar 
      -DgroupId=com.oracle.jdbc -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
$ mvn install:install-file -Dfile=/Users/lassejenssen/Downloads/ucp.jar 
      -DgroupId=com.oracle.jdbc -DartifactId=ucp -Dversion=12.2.0.1 -Dpackaging=jar

Alternative 2: Configure maven to authenticate with your support account

The following alternative is described in both:

https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides (Using a project settings.xml file).

http://www.oracle.com/webfolder/application/maven/index.html (Oracle documentation. You first need to visit the registration site. Then go to chapter 6 in the “Oracle Fusion Middleware Developing Applications Using Continuous Integration document”).

Post a Comment

Your email is never published nor shared. Required fields are marked *