Chapter 4. Building OpenLaszlo from Source

Table of Contents

1. Introduction
2. Philosophy
3. Prerequisites
3.1. Migrating from an existing installation
3.2. Windows
3.3. OS X: Developer Tools and bash
3.4. Clean up Tomcat
3.5. Get Java
3.6. Get the Subversion client
3.7. Get the source
4. Install the tools
4.1. Make sure you have zip
4.2. Get ant 1.6.5
4.3. Install JavaCC
4.4. Install Jython (pre-4.1.0 only)
4.5. Install Python
4.6. Install PyXML
4.7. Install Tomcat 5.0.30
4.8. Install Rhino
5. Set environment variables
6. Install a few libraries automatically
7. Build and run!
8. Notes and gotchas
9. What if it doesn't work?

1. Introduction

These are the instructions for building 4.0.0 and later from source. These instructions may also work for 3.4.x. See 3.x Build Instructions for build instructions for 3.3.x and earlier.

These instructions are fairly well tested, but there may be issues with your particular setup. Please help us make it better by reporting your experience to the laszlo-dev mailing list laszlo-dev mailing list and the Laszlo developer forums.

[Note] Note

This document has been modified from it's original (wiki) format. It has been reformatted to fit your screen.

2. Philosophy

The philosophy of these installation instructions is to create a user-owned-and-operated installation with all of the tools you need in one place. If you follow these instructions, we don't think you will need root access at any point. If you are a power user, use these instructions as guidelines; you can put anything anywhere, so long as you set the correct environment variables defined in setup-lps.sh

3. Prerequisites

You will need Java, Subversion, a command line, and the ability to set environment variables.

If you have firewall software, including Windows Firewall, you might need to open up access to port 8080. We'll mostly be using port 8080, but the other ones are briefly used for controlling server shutdown, startup, and secure connections. Do this with caution; if you don't know what it means to poke a hole in your firewall, you probably shouldn't.

3.1. Migrating from an existing installation

If you already build OpenLaszlo on your machine, but from a source other than Subversion, the cleanest thing to do is to ignore that distribution and start over. You don't need to delete it, but you do need to take references to it out of your path. (For advanced users only: you can keep your tools installed where they are, while changing your LPS-specific environment variables.)

3.2. Windows

To build OpenLaszlo, you're going to need Cygwin. You can almost build and run without Cygwin, but you will suffer, so perform a minimum Cygwin installation.When you install cygwin, be sure to select installation of gcc, subversion, and unzip.

3.3. OS X: Developer Tools and bash

You'll need to install the developer tools in order to compile OpenLaszlo. They can be found on your Mac OS X installation CD, or at developer.apple.com.

All the shell scripts referenced here use the bash shell. That's the default on OS X.

3.4. Clean up Tomcat

Clean up any other Tomcat instances you have running, or any processes which are using port 8080, 8005, or 8043. To find existing Tomcat instances:

Linux
ps -o args -C java
OS X
ps | grep java
Windows

(this stops the LPS instance if it exists)

sc delete LPS

Create a directory to hold the source and tools you're about to install -- for example, C:\Laszlo on Windows, while on OS X and Linux, we like /home/$USER/src/svn.

3.5. Get Java

We recommend using Java 1.5, although reportedly Java 1.6 works as well with later versions (greater than 4.0.2) of OpenLaszlo.

You must get the Java Development Kit (JDK), not the Java Runtime Environment (JRE).

JDK 1.4 Download Page

JDK 1.5 Download Page

JDK 1.6 Download Page

Windows: Install Java in a path with no spaces in the name. That is,

C:\Java\jdk1.5.0_06

not

C:\Program Files\Java\jdk1.5.0_06

Be sure to set JAVA_HOME appropriately.

Mac OS X (10.3 and 10.4) comes with Java 1.4.2 so there is no need to install it. Set JAVA_HOME to /Library/Java/Home. As of mid-April 2006, OS X includes and defaults to Java 5.0. If you have problems, see the Gotchas section at the end of this document.

3.6. Get the Subversion client

General information on Subversion is at subversion.tigris.org. These instructions use the command line client for Subversion.

The package is usually called subversion and the executable is svn. Before you try to install, check if you already have it by going to a command prompt and typing

svn

If the result is "command not found" or something like that, you need to install Subversion. If the result is something like "Do svn help for more instructions", then you do not need to install Subversion. We suggest subversion 1.4 or later; 1.3.2 or later should work.

Windows

There are several options. You can get the .exe binaries directly from Tigris. For a nice GUI, we've had success with TortoiseSVN. Alternatively, use the Cygwin installer: the Subversion package is inside the "Devel" group. Earlier builds of cygwin build of svn (version 1.2.3) might have a problem with properly checking out a source tree. See this posting for details.

If you elect to use the native Windows svn command line client, and also have the cygwin Subversion package, make sure to put it in your bash shell path in front of the cygwin bin directories, so you don't inadvertently use the cygwin 'svn' command by mistake.

OS X
The easy way is to install Subversion using the pre-built binaries. Using Fink or building Subversion from source will probably also work, but then you must know what you're doing.
Linux
If you have a Linux box, you surely know how to install Subversion.

3.7. Get the source

As stated in the philosophy section, these instructions show you how to make a user-owned-and-operated installation. Once you're a power user, you can be clever in all the ways you want to be clever; first-timers should stick to this path, and post on laszlo-dev if they have trouble.

Make a directory in which you'll put all the stuff you're about to get. We recommend $HOME/src/svn for the downloaded code, and $HOME/lib for the libraries you'll have to install.

cd $HOME
mkdir src
mkdir src/svn
mkdir lib

To get the source with Subversion, do

cd $HOME/src/svn
svn co http://svn.openlaszlo.org/openlaszlo/trunk openlaszlo/trunk

Note that the URL is svn.openlaszlo.org, not www.openlaszlo.org. You'll get an Authentication Realm message if you mistakenly use www.

To get the source for a particular branch, say legals, do

svn co http://svn.openlaszlo.org/openlaszlo/branches/legals openlaszlo/branches/legals

This will take a while, because you're getting upwards of 100 MB.

Also get the vendor directory, which contains third-party libraries and applications which are required to build and run the OpenLaszlo server. These are here as a convenience; they are exactly the bits that you would get from each vendor's distribution of that version. Note that there are some tricky version requirements; if you get weird errors, check that you're using the suggested versions.

cd $HOME/src/svn
svn co http://svn.openlaszlo.org/vendor

The tools directory, which provides customized tools written by OpenLaszlo developers, is helpful for development:

cd $HOME/src/svn
svn co http://svn.openlaszlo.org/tools/trunk tools/trunk

You can check these trees out to anywhere you want. We recommend this structure:

$HOME/src/svn/
    openlaszlo/        
        trunk/ this is LPS_HOME if you're working in trunk               
        tags/
        branches/
            branchname/ this is LPS_HOME if you're working in a branch
    tools/    
        trunk/ this is LZ_TOOLS_ROOT
    vendor/ this is LZ_VENDOR_ROOT
$HOME/lib this is LZ_INSTALLS_ROOT

We've created a script to ease configuration. Take a look at tools/trunk/env/setup-lps.sh and the rest of this document might make more sense. This script enables you to specify with command line parameters the location of these directories: openlaszlo, tools, installed libraries, and vendor. The script sets environment variables relative to the specified directories. If you follow the recommended paths in this document, you can just do

$HOME/src/svn/tools/trunk/env/setup-lps.sh

Note the leading dot. You'll have to invoke this setup script in every shell in which you want to do OpenLaszlo development. You might have to edit the script so that the environment variables correspond to your directory structure.

There are a few applications you must install in order to build OpenLaszlo. The Subversion repository contains the installers, but you need to run the installers. Run these installers from the same user account with which you will be developing. We recommend installing these tools into $HOME/lib; this makes it easier to force the tools to use the versions that come with OpenLaszlo.

4. Install the tools

4.1. Make sure you have zip

Check to see if you have at least one of /usr/bin/unzip or /sw/bin/unzip. If you don't have it there are a number of ways you can get unzip. For some reason I didn't have unzip even though I'd installed the Apple developer tools. Supposedly, the Apple developer tools will do it, but Installing fink will work. Another choice is http://www.info-zip.org/ for an easy and free download and install of zip and unzip.

4.2. Get ant 1.6.5

We are using ant 1.6.5. Ant 1.5.* will not work. Ant 1.7 appears to work, although you will get some warnings.

cd $LZ_INSTALLS_ROOT
unzip $LZ_VENDOR_ROOT/apache-ant-1.6.5-bin.zip
export ANT_HOME=$LZ_INSTALLS_ROOT/apache-ant-1.6.5
Windows (no cygwin)
Use the WinZip GUI to unzip apache-ant-1.6.5-bin.zip into your lib directory.
OS X (no unzip)
If you don't have /usr/bin/unzip, you may be able to double-click on apache-ant-1.6.5-bin.zip in the finder, and drag the resulting folder into $LZ_INSTALLS_ROOT (most likely ~/lib).
SUSE Linux
Do not install the ant rpm.

4.3. Install JavaCC

JavaCC is a compiler compiler, like yacc; we use it to help build the compiler. If you want to run the GUI installer:

cd $LZ_VENDOR_ROOT
java -cp . JavaCC2_1

It will ask you where to install to; we suggest $LZ_INSTALLS_ROOT/javacc2.1. It will also tell you to set ~/lib/javacc2.1/bin on your path, but the setup-lps script has taken care of this for you.

If you would prefer the command line installer, add -c to the Java command.

cd $LZ_VENDOR_ROOT
java -cp . JavaCC2_1 -c

4.4. Install Jython (pre-4.1.0 only)

Jython is a Java application that executes Python scripts. Parts of the OpenLaszlo build pipeline are written in Python, but these have been phased out in 4.x.

cd $LZ_VENDOR_ROOT
java -cp . jython-21

Make sure "use jre" is not checked. The GUI will prompt you for the Jython installation directory. We suggest $LZ_INSTALLS_ROOT/jython-21.

If you don't want to use the GUI installer, add -o dir-to-install-to:

java -cp . jython-21 -o ~/lib/jython-2.1

Don't put jython in a system directory; the build will fail if the jython process does not have write access to the jython directory.

NOTE: You can't use the command line installer on Windows_XP because the installer does not understand that XP is Windows. If you get an error about extra bytes at the end of your class file, it is because jython has their own class loader and your Java is puking trying to verify the non-standard class file. Downgrade your java to 1.5 and you will win.

4.5. Install Python

Windows

Run the Python 2.2.2 installer, which is in $LZ_VENDOR_ROOT/Python-2.2.2.exe. Reportedly 2.4.4 and later do not work on Windows.

[Note] Note

If you get a message from the 16 bit MS-DOS Subsystem telling you that C:\WINDOWS\system32\ntvdm.exe got an error "while setting up the environment for the application. Choose 'Close' to terminate the application.", it is likely because you are trying to use the Cygwin version of Python, which just won't do. You need to arrange for the Windows version of Python that you installed above to be found before the Cygwin version is, either by juggling your search path or perhaps uninstalling Cygwin Python.

OS X
OS X comes with Python installed to /usr/bin/python. We're using 2.3.5 successfully.
Linux
Most modern Linux distributions come with Python 2.2 or later. The python-devel package must be installed, too. We have been using Python 2.4.1 on Linux.

4.6. Install PyXML

Windows
Run vendor/PyXML-0.8.win32-py2.2.exe.
Linux and OS X
cd $LZ_VENDOR_ROOT
gunzip PyXML-0.8.3.tar.gz
tar xvf PyXML-0.8.3.tar    
cd PyXML-0.8.3
python setup.py build
sudo python setup.py install

Note: contrary to previous reports, this step is necessary.

[Note] ptw's notes

I install in a non-default place:

sudo python setup.py install --install-lib /usr/local/lib/python2.3/site-packages

I set the --install-lib option so that I won't lose my local extensions if OS X updates Python. I also put the following in my .bashrc so Python sees the local packages:

# we use _xmlplus, which I put here to stay out of the /System dir
export PYTHONPATH=/usr/local/lib/python2.3/site-packages

4.7. Install Tomcat 5.0.30

The Tomcat 5.0.30 installer in our vendor directory is exactly the same as the official Tomcat 5.0.30 release.

Windows
Get the Tomcat 5.0.30 installer from here. Run the installer. When it asks you where to put it, say C:/Tomcat5. Don't start Tomcat; we'll do that later.
Linux and OS X
cd $LZ_INSTALLS_ROOT
unzip $LZ_VENDOR_ROOT/jakarta-tomcat-5.0.30.zip

This installs tomcat into $LZ_INSTALLS_ROOT/jakarta-tomcat-5.0.30/.

Create a user with "admin" and "manager" roles, in jakarta-tomcat-5.0.30/conf/tomcat-users.xml. See this page for details. The build is set up to use user "admin" with password "laszlo", but you can change this in ${LPS_HOME}/build.properties.

The scripts in jakarta-tomcat-5.0.30/bin/* need to be executable; if you know what this means, do this:

# Don't do this if you don't understand chmod. See your local sysadmin.) 
chmod ugo+x jakarta-tomcat-5.0.30/bin/*

4.8. Install Rhino

cp $LZ_VENDOR_ROOT/js.jar $ANT_HOME/lib/

5. Set environment variables

The rest of these instructions require that you set several environment variables. We've created a bash setup script in tools/trunk/env/setup-lps.sh. You can source this script from your .bashrc, or call it interactively. If you don't use our script, your mileage may vary, but we require the following variables to be set:

ANT_HOME, JAVA_HOME, JAVACC_HOME, JYTHON_HOME, TOMCAT_HOME, CATALINA_HOME, LPS_HOME

However you set these variables, you should make sure the directories exist and they're the right ones. If you can't CD to the directory you have a definite problem, and with all the version numbers you might get wrong you'll probably save yourself a lot of frustration if you run this script:

cd $ANT_HOME
cd $JAVA_HOME
cd $JAVACC_HOME
cd $JYTHON_HOME
cd $TOMCAT_HOME
cd $CATALINA_HOME
cd $LPS_HOME
Windows/Cygwin
For Cygwin, WindowsBuilderSetup shows how we set environment variables for a particular Windows machine; use it as a guide for creating your own Cygwin bash script. The number and direction of slashes and quotes is a source of difficulty, but can be fixed with a function called cygpath. As an alternative to WindowsBuilderSetup, here's a variant of the setup-lps.sh that uses cygpath to fix the slash issues and will work on cygwin: cygwin version of setup-lps.sh. Read the comments in the file and call it from your .bashrc.
OS X

Note that in certain circumstances it can be preferable to use Java 1.4.2 instead of Java 1.5, even on versions of OS X where Java 1.5 is the default. The preferred technique for doing this in bash is to set JAVA_HOME as follows:

export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/home/"

To return to Java 1.5, reset JAVA_HOME to its original value:

export JAVA_HOME="/Library/Java/Home"

6. Install a few libraries automatically

(You may need to do this step as root.)

cd $LZ_VENDOR_ROOT
svn up 
cd $LZ_TOOLS_ROOT/build-tools/install-libs
ant

7. Build and run!

Start a new shell so you have all the right environment variables. Then (Windows users running Cygwin, run ant init first, before ant build, in order to copy some required jar files before the compile):

cd $LPS_HOME
ant build 
$TOMCAT_HOME/bin/startup.sh
ant webapp.install

If, during webapp.install, you get java.net.ConnectException: Connection refused: connect, that means Tomcat never started. If you get a HTTP 401 response code, it means that you failed to set up your admin user/password correctly (see above on installing Tomcat).

OS X

OS X 10.4.3 I found that I had to do the following:

bash // This loads the environment variables in setup-lps.sh
cd $LPS_HOME
ant build
cd $TOMCAT_HOME
chmod +x *
$TOMCAT_HOME/bin/startup.sh
bash // for some reason bash exited at the end of startup.sh
cd $LPS_HOME
ant webapp.install

Then point your browser at http://localhost:8080/trunk, or, if you're running a branch or tag, http://localhost:8080/branchname.

In the future, when you have updated your branch(es) with svn up, you will have to repeat this build process.

8. Notes and gotchas

[Note] Note

This section still needs to be copied over from the wiki.

9. What if it doesn't work?

[Note] Note

This section still needs to be copied over from the wiki.