Subject: glue for current native browsers to enable Sun's JVM plugin
To: None <netbsd-java@netbsd.org>
From: BSD For Ever <bsd4ever@draga.com>
List: netbsd-java
Date: 04/16/2004 18:11:45
Hi,

If you have 1.6-current (for the i386 port) and would like to use
Sun's Java Virtual Machine plugin in your NetBSD-native browser(s),
here are some quick steps which do *not* require downloading any
sources nor installing pkgsrc-wip.

If you are running a 1.6-current GENERIC kernel, you already have
option COMPAT_LINUX
and won't even need to rebuild it. Note that COMPAT_LINUX is only
required by the java_vm process; your browser has to be NetBSD-native
for this glue to work.

I'm running a GENERIC kernel from NetBSD-1.6U (dated July 26, 2003)
on an AMD Athlon (686-class) CPU, with 256 MB of RAM and haven't had
any problems running applets inside mozilla-1.6nb1 and firefox-0.8.

OK, this is a dirty hack but if you already have a native browser
you'll be running applets inside it within less than 5 minutes.

Well, here are the steps.


Step 1. If you haven't built mozilla nor firefox yet, do it now :
$ cd /usr/pkgsrc/www/mozilla && make
# cd /usr/pkgsrc/www/mozilla && make install
$ cd /usr/pkgsrc/www/firefox && make
# cd /usr/pkgsrc/www/firefox && make install


Step 2. Go to http://java.sun.com/products/archive/ and then to
http://java.sun.com/products/archive/j2se/1.4.1_07/
and click on the blue "download" below JRE to fetch
j2re-1_4_1_07-linux-i586.bin
Then
$ chmod +x j2re-1_4_1_07-linux-i586.bin
$ ./j2re-1_4_1_07-linux-i586.bin /tmp
# mkdir -p /usr/local/java
# mv /tmp/j2re1.4.1_07 /usr/local/java/sun-1.4.1_07
# chown -R root:wheel /usr/local/java/sun-1.4.1_07


Step 3. Build a tiny shared lib with the following "code" :
$ cat <<EOF >jvm141glue.c
/* jvm141glue.c */

#include <stdio.h>

#ifdef THIS_IS_NOT_REQUIRED_BUT_WONT_HURT_ANYWAY
#undef stdin
FILE *stdin  = &__sF[0];
#endif

#undef stdout
FILE *stdout = &__sF[1];

#undef stderr
FILE *stderr = &__sF[2];

void *__environ=0;
void *__xstat=0;
EOF
$ cc -c -fpic -fPIC jvm141glue.c
Ah, you can skip "-fpic -fPIC" because there is no code.
$ cc -o libjvm141glue.so -shared jvm141glue.o
# mkdir -p /usr/local/lib
# mv libjvm141glue.so /usr/local/lib
# chown root:wheel /usr/local/lib/libjvm141glue.so

Step 4. Backup your /etc/ld.so.conf and create a new one :
# mv /etc/ld.so.conf /etc/ld.so.conf.old
# cat <<EOF >/etc/ld.so.conf
libm.so.0                machdep.fpu_present 1:libm387.so.0,libm.so.0
libXt.so.6               machdep.fpu_present 1:/usr/X11R6/lib/libXt.so
libXt.so.6               machdep.fpu_present 0:/usr/X11R6/lib/libXt.so
libX11.so.6              machdep.fpu_present 1:/usr/X11R6/lib/libX11.so
libX11.so.6              machdep.fpu_present 0:/usr/X11R6/lib/libX11.so
libdl.so.2               machdep.fpu_present 1:/usr/lib/libc.so
libdl.so.2               machdep.fpu_present 0:/usr/lib/libc.so
libstdc++-libc6.1-1.so.2 machdep.fpu_present 1:/usr/lib/libc.so
libstdc++-libc6.1-1.so.2 machdep.fpu_present 0:/usr/lib/libc.so
libm.so.6                machdep.fpu_present 1:libm387.so.0,libm.so.0
libm.so.6                machdep.fpu_present 0:libm.so.0
libc.so.6 machdep.fpu_present 1:/usr/lib/libc.so,/usr/local/lib/libjvm141glue.so
libc.so.6 machdep.fpu_present 0:/usr/lib/libc.so,/usr/local/lib/libjvm141glue.so
EOF


Step 5. Create symlinks in your browser's plugins directory :
# cd /usr/pkg/lib/mozilla/plugins
# ln -s ../../../../local/java/sun-1.4.1_07/plugin/i386/ns610/libjavaplugin_oji.so
# cd /usr/pkg/lib/firefox/plugins
# ln -s ../../../../local/java/sun-1.4.1_07/plugin/i386/ns610/libjavaplugin_oji.so


Step 6 for sh, ksh and bash users :
$ JAVA_HOME=/usr/local/java/sun-1.4.1_07
$ export JAVA_HOME
$ ulimit -S -d 262144

Step 6 for csh and tcsh users :
  setenv JAVA_HOME /usr/local/java/sun-1.4.1_07
  limit datasize 262144

Note that 262144 is the minimum required, but you can increase that.
Also note that you don't need to add ${JAVA_HOME}/bin to your PATH,
although it would be usefull if you also install the jdk.


Step 7. Try some applets with firefox and/or mozilla :
First type about:plugins to make sure your plugin was detected.
Then go to http://java.sun.com/applets/ to try some applets.
Both firefox-0.8nb1 and mozilla-1.6nb1 run all these :
http://java.sun.com/applets/other/AudioItem/
http://java.sun.com/applets/other/BouncingHeads/
http://java.sun.com/applets/other/Bubbles/
http://java.sun.com/applets/other/Bullets/alphabullet.html
http://java.sun.com/applets/other/Bullets/huebullet.html
http://java.sun.com/applets/other/Hangman/
http://java.sun.com/applets/other/ImageLoop/
http://java.sun.com/applets/other/ImageTest/
http://java.sun.com/applets/other/ScrollingImages/
http://java.sun.com/applets/other/TumblingDuke/
http://java.sun.com/applets/other/UnderConstruction/
http://java.sun.com/applets/other/WordMatch/
http://java.sun.com/applets/archive/beta/Abacus/
http://java.sun.com/applets/archive/beta/Cannon/
http://java.sun.com/applets/archive/beta/Crossword/
http://java.sun.com/applets/archive/beta/Escher/
http://java.sun.com/applets/archive/beta/LED/
http://java.sun.com/applets/archive/beta/NeonSign/
http://java.sun.com/applets/archive/beta/Pythagoras/
http://java.sun.com/applets/archive/beta/Voltage/

These either freeze, crash or yeld "Applet <name> notinited" :
http://java.sun.com/applets/other/Bullets/dukebullet.html
http://java.sun.com/applets/archive/beta/DiningPhilosophers/
http://java.sun.com/applets/archive/beta/NuclearPlant/
http://java.sun.com/applets/archive/beta/StarField/
http://java.sun.com/applets/archive/beta/SystemInfo/


Notes:

To get rid of step 6, add
        JAVA_HOME=/usr/local/java/sun-1.4.1_07
        export JAVA_HOME
        ulimit -S -d 262144
to /etc/profile
and
        setenv JAVA_HOME /usr/local/java/sun-1.4.1_07
        limit datasize 262144
to /etc/csh.cshrc

Also note that you can use the ldd from pkgsrc/emulators/suse_base
before and after step 4 to check that your /etc/ld.so.conf is OK :
/emul/linux/usr/bin/ldd /usr/local/java/sun-1.4.1_07/plugin/i386/ns610/libjavaplugin_oji.so

Why did I use 1.4.1_07 instead of 1.4.2_04 which is handled by
pkgsrc/lang/sun-jre14 ? Well, because Sun recommends the former to
those having problems with the latter.

Happy appleting!

RSET