Appendix B. Installing Jython on Linux

CONTENTS
  •  Unpacking the Blackdown Package
  •  Unpacking the Sun Package
  •  Installing the Sun and Blackdown Distributions
  •  Installing Older Distributions
  •  Running Jython

Jaysen Lorenzen

To illustrate the installation of Jython on Linux, we're using the most recent version of the SDK 1.3 glibc. Versions 1.2 and 1.3 are available only for newer distributions using the libc6 libraries (such as Red Hat v.5.x and Debian v.2.x). The libc5 versions of J2SE v.1.1x are available on the Blackdown site for those of you running older distributions.

If you're the root user of your Linux system, log in as root, or use the su command to gain "superuser" (that is, root) privileges before trying each install. If you're not the root user, you can install software only to your own user directory /home/<your name> or to directories for which you have read, write, and execute access. (If you want to install on a machine other than your own, you may have to ask your system administrator for help.)

The first step in your Linux Jython install is downloading the J2SE (v.1.3) from Blackdown (http://www.blackdown.org), from which you'll get a compressed tar ball, or Sun Microsystems (http://java.sun.com), from which you'll get a self-extracting package. The next step is unpacking the J2SE and installing it.

Unpacking the Blackdown Package

Many, many versions of the J2SE are available from Blackdown. I chose the latest, j2sdk1.3 (j2sdk-1.3.0-RC1-linux-i386.tarbz2). Only a bziped package is offered for this release, but earlier releases come with standard gziped packages.

In a shell, as the root, or using the su command, copy or move the downloaded file to a directory. This directory can be any one you want, but /usr/local/lib is the best choice because it makes it easier for other users to find examples and documentation. (Thus, the J2SE subdirectory is /usr/local/lib/j2sdk1.x). Then unzip and untar the file by changing the directory to its location with the command

bzip2 -dc j2sdk-1.3.0-RC1-linux-i386.tar.bz2 | tar -xvf-

If you downloaded a gziped package, replace bzip2 with gzip in the command.

HotSpotClient

The default virtual machine for J2SDK v.1.3 is HotSpotClient. If it doesn't work well with Jython, change it by editing the file.

/<jdk1.x>/jre/lib/jvm.cfg

(where <jdk1.x> is the jdk install directory)

Moving "-classic" to the first line of the file will change the default to Linux Native Threads.

Unpacking the Sun Package

Here we're using J2SDK v.1.3 and the self-extracting binary package (j2sdk-1_3_0-linux.bin). In a shell, as the root, or using the su command, copy or move the downloaded file to the directory of your choice again we're using user/local/lib, so the J2SE subdirectory is /user/local/lib/jdk.1.x.

Make the file executable with the command

chmod a+x j2sdk-1_3_0-linux.bin

Execute it with the command

./j2sdk-1_3_0-linux.bin

This launches a script and displays the license agreement from Sun (which you must read and accept). The script unpacks and installs the SDK.

Installing the Sun and Blackdown Distributions

The installation procedures that follow are common to both Sun and Blackdown.

First we have to set some environment variables. There are several ways to do this, all of which depend on user rights and preferences.

Setting the Environment Variables

To set PATH and CLASSPATH, edit the rc file in your home directory for the shell you're using. I've chosen the bash shell, so the file to edit is ~/.bashrc. If a PATH statement exists, add the following line just below PATH=etc/etc.

PATH=$PATH:/<jdk1.x>/bin

where <jdk1.x> is the J2SE directory, including the complete path created in the previous steps. If there are any references to older J2SE versions here, remove them. You should see

PATH=$PATH:/usr/local/lib/j2sdk1.3/bin

If there's no CLASSPATH statement, add it. If there is one, add the following line after it:

CLASSPATH=/<jdk1.x>/lib/tools.jar:./

where <jdk1.x> is the J2SE directory, including the complete path created during the previous steps.

Remove any references to older J2SE versions in the path. You should see

CLASSPATH=/usr/local/lib/j2sdk1.3/lib/tools.jar:./

If you don't see a CLASSPATH statement, add either the PATH=$PATH or the CLASSPATH line shown above. If you see an export statement, append a space, the word PATH, another space, and the word CLASSPATH to it. If you don't see an export statement, create one containing PATH and CLASSPATH at the bottom of the file.

export PATH CLASSPATH

Now you should have these PATH, CLASSPATH, and export lines:

PATH=$PATH:/usr/local/lib/j2sdk1.3/bin CLASSPATH=/usr/local/lib/j2sdk1.3/lib/tools.jar:./ export TERM PATH CLASSPATH

Save and close the file. Then re-execute the shell you're working in so that the environment changes will take effect.

If the computer you're on is yours or if your system administrator is by your side, you can set the PATH and CLASSPATH variables globally as root (regardless of the shell used) by editing the /etc/profile file and making the same changes as for the bash shell.

Installing Older Distributions

If you're downloading a J2SE version older than 1.2, you'll have to get the JFC/Swing classes from the JavaSoft site (http://java.sun.com/products/jfc/#download-swing). Make sure your J2SE and JFC versions match for example, if you have J2SE v.1.1.7, you need Swing v.1.1.1 (swing1_1_1.tar.Z).

Tar/Zip

The download page doesn't mention Linux, so choose the standard tar or zip file, not the installer.

In a shell, as root, or with the su command, copy or move the downloaded file to the directory you choose. As before, we're using /usr/local/lib and we want the swing-1.1.x directory (/usr/local/lib/jdk1.1.7/swing-1.1.x), so we move the file to /usr/local/lib/jdk1.1.7/. Installing the Swing classes in the J2SE directory makes it easy for all users to find the examples and the documentation.

Unzip and untar the downloaded file by changing the directory to its location (/usr/local/lib/jdk117_vla) with the command

gzip -dc swing1_1_1.tar.Z | tar -xvf-

which creates the Swing subdirectory.

Add the swing.jar file to the CLASSPATH variable by modifying the CLASSPATH line in the personal ~/.bashrc file or the global /etc/profile file.

CLASSPATH=$CLASSPATH:/<base path>/<swing path >/swing.jar

/<base path>/<swing path>/ is the complete path to swing.jar. If you installed J2SE v.1.1.7, the path should look like

CLASSPATH=$CLASSPATH:/jdk117_v1a/swing-1.1.1fcs/swing.jar

Save and close the file. You'll have to restart the shell for the environment changes just made to take effect.

Installation Alternatives

There are countless ways to install the J2SE on Linux. For distributions using RPM package managers (like those here), RPM and DEB packages are available, which you can find on the Linux distribution FTP site.

Testing the Installation

Test your install by starting a shell and entering java version. You should get a message like this:

[jaysonl@r_monkey lib]$ java -version java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.3.0-RC1) Classic VM (build Blackdown-1.3.0-RC1, native threads, sunwjit)

If you don't, there may be something wrong. Try entering the complete path to the Java executable, which in our case is

[jaysonl@r_monkey /]$ /usr/local/lib/j2sdk1.3/bin/java -version

The appropriate response means that you have a problem with your environment variables. Check the rc file for your shell or the /etc/profile file to make sure the paths are correct. (Remember, you have to re-execute the shell for the changes to take effect.)

If you get a "Segmentation Fault" message, chances are you installed the wrong binary release of the J2SE. If you're using an older Linux distribution (older than Red Hat v.5.x or Debian v.2.x) and chose the glibc binary, you may find you need libc5 instead. Check your Linux distribution references for the correct library type.

If the virtual machine displays "Font specified in font.properties not found," edit the file:

/<jdk1.x>/jre/lib/font.properties

where <jdk1.x.> is the J2SE install directory. Comment out the fonts that weren't found to stop these warning messages. Installing the fonts is an alternative solution.

If none of these quick fixes does the trick, you have a problem. Refer to the Blackdown installation FAQ page (http://www.blackdown.org/java-linux/docs/faq/FAQ-java-linux.html#toc4) for advice.

Downloading the Jython and CPython Libraries

If all went well with the installation, you can download the Jython and the CPython libraries from http://www.jython.org or http://www.python.org. Then, in a shell, as root, or using the su command, change the directory to which you downloaded the class file by entering

java Jython1x

where 1x is the number of the downloaded Jython version.

In our case, the command looks like

java Jython11

This launches the java GUI version of the install shield and walks you through a series of questions. One question is which directory you want to install Python in. The default is your home directory if you've logged in as root. (Once again, although you can choose any directory I recommend /usr/local/lib.). The result is the creation of a directory called Jython-1.x in the directory specified. To install Jython, replace the Jython11 install class with its Jython counterpart.

The next step is to edit your environment variables (here, in the ~/.bashrc file) by adding the following just below the existing PATH statement:

PATH=$PATH:/<Jython-1x>

where <Jython-1x> is your chosen directory and the number of the Jython version you've downloaded. Here's the actual line:

PATH=$PATH:/usr/local/lib/Jython-1.1

Now add the following CLASSPATH line just below the existing one:

CLASSPATH=$CLASSPATH:/<Jython-1.x>/Jython.jar

where <Jython is the installation directory and -1.x> is the Jython version installed in our case,

CLASSPATH=$CLASSPATH:/usr/local/lib/Jython-1.1/Jython.jar

Save and close the file, and then restart your shell so the changes take effect.

If It's Your First Time

To start Jython for the first time, you need to be the root user or use the su command (to gain superuser privileges). The first run creates some new directories and searches your path to find the J2SE-installed Java classes.

Running Jython

To run Jython for the first time, type Jython at the prompt, and press Enter. You should see something like this:

packageManager: processing new jar,"/usr/local/lib/Jython-1.1/jython.jar" packageManager: processing new jar,"/usr/local/lib/j2sdk1.3/lib/tools.jar" packageManager: processing new jar,"/usr/local/lib/j2sdk1.3/jre/lib/rt.jar" packageManager: processing new jar,"/usr/local/lib/j2sdk1.3/jre/lib/i18n.jar" packageManager: processing new jar, "/usr/local/lib/j2sdk1.3/jre/lib/sunrsasign.jar" Jython 1.1 on java1.3.0 (JIT: sunwjit) Copyright (C) 1997-1999 Corporation for National Research Initiatives

Then press Ctrl-D to exit interactive mode.

If you want to use parts of the standard Python library that aren't included with Jython, you have two choices. You can download and install them from the Jython download page (recommended by the folks at the Jython site because the Python v.1.5.2 libs version has been modified to work better with Jython):

http://www.jython.org/download.html#pylib

or you can add a pointer in python.path to the lib directory of a CPython distribution (try this with your system administrator by your side).

In a shell, as root, or using su, change the directory to the one you downloaded the CPython class file to, and enter

jython -jar pylib152e.jar

There will be a flurry of activity on the screen as the CPython libraries are extracted, copied, and compiled to your directories. Your installation is now complete.

CONTENTS


Python Programming with the JavaT Class Libraries. A Tutorial for Building Web and Enterprise Applications with Jython
Python Programming with the Javaв„ў Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython
ISBN: 0201616165
EAN: 2147483647
Year: 2001
Pages: 25

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net