DæmonNews: News and views for the BSD community

Daemon News Ezine BSD News BSD Mall BSD Support Forum BSD Advocacy BSD Updates

Doing Java on NetBSD

Graham Jenkins <grahjenk@au1.ibm.com>

KeepAlive Application

Java has been hailed as the language in which one can write a program once, and run it everywhere. There is another version of this assertion in which the phrase "debug everywhere" appears. I decided to try out some Java programs on a basic NetBSD machine. The major issue here was finding an appropriate version of the Java Virtual Machine (JVM).

The Programs

The first program I needed to run on a NetBSD platform was "A KeepAlive Program You Can Use Anywhere". It was written in Java, and it even worked on Windows 95 using the Microsoft 'jview' run-time environment. This program makes a periodic name-service request, then uses the AWT classes to change some status-light colors and frame titles.

I also needed to run a Java implementation of the Brother-Internet-Print client whose Perl predecessor can be found at CPAN. An appropriate set of documentation can be found with it; the Java version looks for an extra ('S') record in its configuration file to define the SMTP gateway(s) it should use.

The BIPclient.java program takes an incoming data stream and breaks it into parts small enough to pass through whatever mail gateways you use, then encodes and mails each part. It accomplishes this by using the JavaMail extension and the Java Activation Framework.

The Hardware

Each of the above-mentioned programs is conservative in its resource requirements, so I installed both the source files and their corresponding 'jar' files on an ancient Intel 486 running NetBSD 1.6.1 with 24MB of memory.

Compiling With GCJ

You don't have to compile Java programs for a particular target architecture; remember, you are supposed to compile them once, and run them anywhere! However, there is a GNU Compiler for Java (GCJ) which comes with more recent versions of GCC. This can compile Java source files into native executables. It has been designated by some as an "ahead-of-time compiler" so as to contrast it with those Java Runtime Environments (JRE's) where class-file portions can be compiled into native code on a "just-in-time" basis according to usage patterns. Unfortunately, GCJ is not included in the version of GCC which is normally installed with NetBSD 1.6.1. So I had to add the 'gcc-3.2.1' package, and adjust some environment variables accordingly. GCJ works well for "Hello World" programs. But it doesn't handle class-files written by Sun Microsystems, and it doesn't do AWT operations real well either. Right now, for programs like mine, it's about as useful as udders on a bull.

Blackdown Java

My next choice was the 1.3.1-02a_FCS Java Runtime Environment (JRE) from Blackdown Java. It's a Linux executable, so I had to revert to a kernel which included Linux support, and install the suse_base-7.3nb2, suse_compat-7.3 and suse_x11-7.3nb2 packages. This executed the KeepAlive program straight up. But there were problems with the Print client timing out whilst establishing an SMTP connection; installation on a Pentium III solved these. For those who are wondering why I didn't use the 1.4.1-01 JRE from Blackdown... it doesn't work with NetBSD 1.6.1; something to do with thread handling.

Kaffe

Running a Java Virtual Machine (JVM) under a Linux emulation on a NetBSD machine never seemed like a good idea to me. I recently downloaded the Kaffe 1.1.0 source code and compiled it on the Intel 486. The Print client now works on that machine!

Kaffe 1.1.0 includes its own runtime environment and requires no additional packages if you compile it yourself. A check is made for X header files during compilation, so you need to ensure that these exist before you start (e.g. install 'xcomp.tgz'). The real bonus with Kaffe is that it runs on non-Intel architectures.

Compiling with Kaffe or Jikes

Kaffe also includes a Java compiler; it's actually implemented in Java, so it's not real fast. If you want fast compilation with good diagnostics, you should install the Jikes compiler.

The jikes-1.18 package is available in the NetBSD package collection.

FootNote - LPD Filter for the Print Client

To pass jobs to the Print client, you need an LPD input filter as shown hereunder.

	#  $NetBSD: printcap,v 1.10.2.2 2002/08/27 01:38:08 hubertf Exp $
	#  from: @(#)printcap      8.1 (Berkeley) 6/9/93
	tg26wB|Lexmark Optra W810:\
	  :lp=/dev/null:sd=/var/spool/output/tg26wB:\
	  :if=/usr/local/lpdfilters/tg26wB:lf=/var/log/lpd-errs:mx#0:sh:

	#!/bin/sh
	# @(#) tg26wB  LPD input filter to feed BIPclient.jar program.
	PATH=/usr/bin:/usr/local/kaffe/bin
	# Un-comment the following line if you have LPRng.
	# exec java -jar /usr/local/bin/BIPclient.jar "$@"
	# Else ensure that the basename of this program matches the printer-name.
	exec java -jar /usr/local/bin/BIPclient.jar -P `basename $0` "$@"
Google
Web daemonnews.org

More Articles
  • Interview with Jan Schaumann
  • Interview with Theo de Raadt
  • Book Review: Virtualization with VMware ESX Server
  • Editorial: Not Quite Dead Yet
  • The Design of OpenBGPd
  • Interview with der Mouse
  • Letter to Steve Jobs
  • Interview with Manuel Bouyer on Xen
  • Apple and Open Source
  • BSDCan 2006
  • BSD Certification Survey Results
  • Lab in a Box
  • Ike Notes on BSDCan 2005
  • BSDCan 2005 Photos
  • FreeBSD Developer Summit Pictures

  • Advertisements




    Author maintains all copyrights on this article.
    Images and layout Copyright © 1998-2006 Dæmon News. All Rights Reserved.