Zorba - Mac OSX Installation

Guide to Zorba installation on Mac OSX

This is a guide to install Zorba on Mac OSX, it was tested on OSX 10.8.5 Mountain Lion with Xcode 5.0 and Zorba 2.9.1. Send us email with the results you had on different versions or platforms.There are 3 ways to get Zorba running on your Mac:

Prerequisites

  • Apple Mac OSX 10.8.5 Mountain Lion
  • Apple Xcode Developer Tools version 5.0 (might work with 4.4 or later too)
  • For a) and c) MacPorts 2.2.0 (see below).

Install MacPorts

Install MacPorts 2.2.0: http://www.macports.org/install.php . The easiest way to install MacPorts on a Mac OS X system is by downloading and running the .dmg file.Update MacPorts
$ sudo port -v selfupdate
Upgrade outdated packages (this might take a while depending on the outdated packages).
$ sudo port upgrade outdated

a) Install Zorba binary from .pkg file

The zorba-2.9.1.pkg file contains only Zorba installation files but not it's dependecies. Unlike Linux and Windows distributions, it contains both Zorba runtime with core modules and most of the external modules. It does not contain the folowing external modules: image, schema-tools, read-pdf and email, due to lack of macports of these modules dependencies. If one of these modules is required, then Zorba must be installed from source.Make sure you have MacPorts installed and up to date. Since .pkg contains only Zorba installation files, it's dependecies need to be installed too.Install dependecies:
sudo port install boost curl icu libiconv libxml2 libxslt xerces3 tidy fop geos libarchive sqlite3 swig swig-python swig-php swig-java swig-ruby
Note: Use MacPorts installation of the libraries, do not modify the libraries that ships with OSX. Modifying OXS libraries usualy renders your OSX installation unusable.Download the zorba .pkg file (aproximately 12MB) : zorba-x.pkg.Install it by running it, a MacPorts gui installer will guide you.after installation Zorba binary should be available in: /opt/local/bin/zorba.To uninstall Zorba files, use the folowing script: zorba-2.9.1-uninstall.sh.

b) Install Zorba binary from .mpkg file

This is the easies way to install Zorba since it doesn't require installation of MacPorts and requires download and installation of only one file.
  • The Zorba .mpkg file contains both the Zorba installation files and also all it's MacPorts dependecies. This makes the zorba-2.9.1.mpkg a 175MB file.
  • Similar to .pkg file, the .mpkg file contains the Zorba runtime, core modules and most of the external modules. It does not contain the folowing external modules: image, schema-tools, read-pdf and email, due to lack of macports of these modules dependencies. If one of these modules is required, then Zorba must be installed from source.
Download the zorba .mpkg file (aproximately 175MB) : zorba-x.mpkg.Install it by running it, a MacPorts gui installer will guide you.Zorba binary should be available in: /opt/local/bin/zorbaTo uninstall only Zorba files, use the following script: zorba-2.9.1-uninstall.sh. For the rest of the packages use their own recommendations.

c) Install Zorba from sources

This is the most flexible way of installing Zorba, one has access to all it's build configuration and has the opportunity to select the required external modules including the image, schema-tools and read-pdf.This requires instalation of < href="http://www.macports.org/install.php">MacPorts 2.2.0 and installation of Zorba dependecy ports:
sudo port install boost curl icu libiconv libxml2 libxslt xerces3 tidy fop geos libarchive sqlite3 swig swig-python swig-php swig-java swig-ruby
For more details on configuring and building Zorba from sources see: Note: Make sure you don't have any binary Zorba versions instaled, if you do you need to uninstall them in order to have Zorba build correctly from your sources.

Working with Python

The installer puts the Zorba python library in: /opt/local/share/python/, so this path needs to be added to system path.The contents of test.py:
import sys
sys.path.insert(0, '/opt/local/share/python/')
import zorba_api

print "Running: Get zorba instance and shutdown"

store = zorba_api.InMemoryStore_getInstance()
zorba = zorba_api.Zorba_getInstance(store)
zorba.shutdown()
zorba_api.InMemoryStore_shutdown(store)

print "Success"
Since the installer is done by MacPorts, the MacPorts python needs to be used. To run the test python script use:
/opt/local/bin/python2.7 test.py
A list of other python examples can be found in doc/python/examples and swig/python/tests/.

Working with PHP

The Zorba library for PHP is installed under: /opt/local/share/php5/. PHP needs a php.ini configuration file that has to contain:
extension_dir=/opt/local/share/php5/
include_path=/opt/local/share/php5/
The test.php file should look like:
<?
require 'zorba_api_wrapper.php';

print "Running: Get zorba instance and shutdown\n";

$store = InMemoryStore::getInstance();
$zorba = Zorba::getInstance($store);

$zorba->shutdown();
InMemoryStore::shutdown($store);

print "Success";
?>
To run the script use:
php -c path/to/php.ini/ test.php
A list of other PHP examples can be found in doc/php/examples and swig/php/tests/.

Working with Ruby

The Zorba library for Ruby is installed under /opt/local/share/ruby/zorba_api.bundle.The test.rb file contains:
require '/opt/local/share/ruby/zorba_api'

print "Running: Get zorba instance and shutdown"

store = Zorba_api::InMemoryStore.getInstance()
zorba = Zorba_api::Zorba.getInstance(store)
zorba.shutdown()
Zorba_api::InMemoryStore.shutdown(store)

print "Success"
To run the script execute:
ruby test.rb
A list of other Ruby examples can be found in doc/ruby/examples and swig/ruby/tests/.

Working with Java

To make Java work with Zorba, the Zorba library needs to be on the path and the Zorba jars need to be on the class path. Zorba library and jars are installed under /opt/local/share/java.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/local/share/java
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/opt/local/share/java
export CLASSPATH=$CLASSPATH:/opt/local/share/java/zorba_api.jar:/opt/local/share/java/zorba_xqj.jar:/opt/local/share/java/xqjapi.jar
Compile and run your files as usual:
javac -cp $CLASSPATH Test.java
java -cp $CLASSPATH:. Test
A simple source on how to use it in code:
import javax.xml.xquery.*;
import org.zorbaxquery.api.xqj.*;

class Test
{
   static
   {
     System.loadLibrary ( "zorba_api" );
   }
   
   public static void main(String[] args) throws XQException
   {
     System.out.println("Test Zorba");
             
     ZorbaXQDataSource xqds = new ZorbaXQDataSource();
     XQConnection xqc = xqds.getConnection();
     XQExpression xqe = xqc.createExpression();
     XQResultSequence result = xqe.executeQuery("1+2");

     while (result.next()) {
       // Print the current item in the sequence
       System.out.println(">   " + result.getItemAsString(null));
     }

     xqc.close();
   }        
}
A list of other Ruby examples can be found in doc/xqj/examples and swig/xqj/managers/.