GlassFish 3 and Oracle 10g XE on Ubuntu Linux 9.10

This is an example infrastructure setup for a development environment which uses Oracle database 10g XE and GlassFish 3 as application server on an Ubuntu Linux 9.10.

I wrote this blog post because I wanted to use GlassFish and Oracle XE on my laptop to test some examples and I thought maybe someone else could find this step by step guide useful.

Oracle 10g XE installation

Note: Some of the explanation how to install Oracle on ubuntu is based on the wiki entry from the ubuntu site. See https://help.ubuntu.com/community/Oracle10g.

Ubuntu 64bit

If you try to follow this tutorial with an Ubuntu 64 bit check out the following site post Oracel 10g XE on Ubuntu 10.10 (64bit).

Before we install Oracle XE with apt-get we need to download and add the Oracle public key as trusted key.

wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle
sudo apt-key add RPM-GPG-KEY-oracle

Add the Oracle sources to /etc/apt/sources.list file.

deb http://oss.oracle.com/debian unstable main non-free

Update the sources and install Oracle XE.

sudo apt-get update
sudo apt-get install oracle-xe-universal

After the installation we can configure our Oracle XE installation with the following command.

sudo /etc/init.d/oracle-xe configure

The script asks for some configurations settings. It is important that you set the port for Oracle Application Express not to 8080, because GlassFish will use this port for the web applications. So we use instead the port 8081 for the Oracle Application Express (APEX).

Specify the HTTP port that will be used for
Oracle Application Express = 8081

Specify a port that will be used for the
database listener = 1521

Specify a password to be used for database
accounts (SYS and SYSTEM) = system

Do you want Oracle Database 10g Express
Edition to be started on boot  = yes

Note: When the option startup on boot is set to NO then you will have problems to start and stop Oracle XE with the /etc/init.d/oracle-xe script. See http://forums.oracle.com/forums/thread.jspa?threadID=944382 for more details.

When you have problems (set started on boot = NO) this workaround could help. Start Oracle XE with

sudo /etc/init.d/oracle-xe enabled
sudo /etc/init.d/oracle-xe start

and stop it with

sudo /etc/init.d/oracle-xe stop
sudo /etc/init.d/oracle-xe disabled

Note: With the script argument enabled / disabled you specifies if Oracle XE should automatically start when the system starts up.

The next step is to adjust the PATH settings, so that we can use sqlplus on our command line. The PATH variable is set in the .bashrc file.

.bashrc

ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_HOME
export ORACLE_SID=XE

export PATH

After the installation there are some shortcuts (Start Database, Run SQL Command Line, etc.) in our start menu so we need to add our system user to the dba group so that we are allowed to use them.

sudo usermod -g dba my_user

We create a directory where Oracle can store our tablespaces and give the system user oracle the rights to this directory.

sudo mkdir /var/local/oracle
sudo chown oracle /var/local/oracle/

Setup the database

To create a tablespace and database user we start sqlplus as database user system.

sqlplus system/my_password

For our example we create a tablespace glassfish_app and a database user. I created just a simple tablespace with the size of 10M and a maximum size of 200M. Be sure that your project have other requirements and adjust this settings to your need. See http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7003.htm for more details.

CREATE TABLESPACE glassfish_app DATAFILE '/var/local/oracle/glassfish.dbf'
     SIZE 10M
     AUTOEXTEND ON NEXT 200K
     MAXSIZE 200M;

For the tablespace glassfish_app we create our user glassfish and give him all rights. In a more serious environment you have to specify the privileges a bit better than I did.

CREATE USER glassfish
    IDENTIFIED BY glassfish
    DEFAULT TABLESPACE glassfish_app;

GRANT ALL PRIVILEGES TO glassfish;

GlassFish installation

Download the Platform-independent GlassFish (Full Platform) 3.0.1 ZIP from the GlassFish homepage and unzip the file.

unzip glassfish-3.0.1.zip

There should now be the directory glassfishv3 with the follwing content.

glassfishv3
            |-- bin
            |-- glassfish (1)
            |-- javadb (2)
            |-- mq (3)
            '-- pkg
  1. GlassFish the application server
  2. The Derby database
  3. Open MQ the message broker

Next we need to install Java SDK 6.

sudo apt-get install sun-java6-jdk

Note: GlassFish Installations require JDK 6. The minimum and certified version required version is 1.6.0_20. This is not a problem with the newest update of Ubuntu Linux 9.10 (Karmic Koala).

Again we modify our .bashrc file and add the GlassFish directory to the PATH variable. Set the $GLASSFISH_DIR variable to the directory where you have unzipped your GlassFish installation.

.bashrc

GLASSFISH_DIR=/home/mr/bin/glassfishv3
GLASSFISH_HOME=$GLASSFISH_DIR/glassfish
DERBY_HOME=$GLASSFISH_DIR/javadb
OPEN_MQ_HOME=$GLASSFISH_DIR/mq

PATH=$PATH:$GLASSFISH_HOME/bin:$DERBY_HOME/bin:$OPEN_MQ_HOME/bin
export GLASSFISH_HOME
export DERBY_HOME
export OPEN_MQ_HOME

export PATH

To use the scripts from Open MQ and Derby we put their bin directories also into the PATH variable.

The next step is to add the Oracle JDBC driver to the GlassFish lib directory. You should find the Oracle JDBC driver ojdbc14.jar in $ORACLE_HOME/jdbc/lib. Copy the ojdbc14.jar in your GlassFish domain lib/ext directory. The default domain in GlassFish is named domain1, so when your domain has a different name you should replace domain1 with your GlassFish domain name.

cp $ORACLE_HOME/jdbc/lib/ojdbc14.jar \
    $GLASSFISH_HOME/domains/domain1/lib/ext

Note: When you want to install GlassFish 3 as service then these blog entries could help you:

GlassFish configuration

Now we have to start GlassFish and go to the GlassFish admin console http://localhost:4848

asadmin start-domain

Note: By default there is no password set. A password can be set in the menu Enterprise Server > Administrator Password.

We create now our Connection Pool with the following settings.

Pool Name: OraclePool
Resource Type: javax.sql.DataSource
Datasource Classname: oracle.jdbc.pool.OracleDataSource

In the additional properties we have to set password, username and the connection url.

URL: jdbc:oracle:thin:@localhost:1521:xe
Password: glassfish
User: glassfish

To test the connection click on the ping button. When all settings are valid you should receive a “ping succeeded”.

Note: When the ojdbc14.jar is note found you should get a message like Class name is wrong or classpath is not set for : oracle.jdbc.pool.OracleDataSource Please check the server.log for more details.

The next step is to create a JDBC resource. Here we specify the Connection Pool and a JNDI name for our JDBC resource which can be used by our next Java EE project.

JNDI Name: jdbc/dbOraclePool
Pool Name: OraclePool

Finally…

So it’s time for the fun part create a Java EE project which uses our new JDBC resource.
I hope this post was useful and you get a quick start to setup your development infrastructure.

4 thoughts on “GlassFish 3 and Oracle 10g XE on Ubuntu Linux 9.10

  1. It’s very nice, I try it on my notebook, but I have not any x86 installation at home(server, notebook and desktop are x64_86)

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>