5/20/2015

Developing Liferay with Oracle

If you´re working on a mac, like I do, and you´re working on a lot of customer projects then you might run into the situation where you have to use an Oracle database instead of the standard MySql one. This blog post is about how to download, configure, connect and developer with Oracle and liferay.

Getting the VM

You can download and install an Oracle VM for your mac computer at no cost. Just download it from this page : https://tech.lds.org/wiki/Oracle_VM  (Direct download link: Download the Oracle VM Appliance Zip ). I have to thank those guys at LDSTech - they have a created an easy to use and understandable instruction set to get Oracle running on macintosh. I will copy most of their stuff here so that it doesn´t get lost in case they modify their page.

So please download the VM from the link above, and while you´re doing so, please also download VirtualBox. You will need it to run the vm image. You can download it here: Download and install VirtualBox

Unzip the vm file and import it into VirtualBox. Start the VM and it will begin configuring itself. Just go and get yourself a cup of coffee: This might take a while. Once it is done, the machine will shutdown itself. Don´t shut it down manually, let it finish.

Once the machine is ready, you need to configure the ports in order to forward all calls to the oracle installation to the vm. Select the network settings of your virtual machine, leave the "Attached to" value as NAT and expand the Advanced options, then click Port Forwarding and add the following rules:
  • Rule 1: Host Port = 1521, Guest Port = 1521
  • Rule 2: Host Port = 9999, Guest Port = 8080

This way you make sure, the web administration console is accessible even though you have a running liferay server on your computer. Restart the VM and you should be able to access the oracle xe admin console using this url : http://localhost:9999/apex and then see the following:


To administer your Oracle XE instance using the web admin gui, the username is SYSTEM and the password is oracle. Log in and have fun !

Preventing a common error in a complex liferay environment

Before we actually connect liferay to oracle, we need to prevent one common error that happens, when you have a complex liferay installation: maximum number of sessions exceeded. When you run liferay with oracle you might see one of these error messages (together with a stacktrace) in your concole:


  • ORA-00018: maximum number of sessions exceeded
  • ORA-00020: maximum number of processes (%s)
  • TNS Name Not Found -


This error of umber of concurrent sessions and processes is a common problem with oracle vanilla installations and we can fix it pretty easily. First, we need to enter the administration console of our oracle xe installation.If you want to log in to your oracle installation using the command line you you need to do so from the virtual machine. No problem: It is a fully functional linux installation :) So login into your linux VM using ldstech / ldstech.





Next, we need to run sqlplus to let us into the actual database. Enter the following: sqlplus system@XE as sysdba .

To set the values to a proper amount, enter the following :


alter system set sessions=300 scope=spfile;
alter system set processes=300 scope=spfile;


After that just restart your VM and the changes should have taken effect.


Using Oracle with liferay


Now that you have oracle up and running, it is time to connect liferay to use it. Create an oracle database (aka create an oracle user) named "lportal", assign all neccessary rights and startup liferay. Upon your first start liferay will ask you to choose a database provider. We will choose Oracle and enter the following data:

jdbc.default.username=lportal
jdbc.default.password=lportal
jdbc.default.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.default.url=jdbc:oracle:thin:@localhost:1521:xe



Using SQL Developer


My standard Tool to connect to an oracle XE database is the Oracle SQL developer. You can download it here: SQL Developer Download



Install it, start it up and then create a new connection. This Screenshot shows you, what to enter into the various configuration fields and after that you should be good:






If you have any questions, feel free to leave a comment.