18c2ecf20Sopenharmony_ciJava(tm) Binary Kernel Support for Linux v1.03
28c2ecf20Sopenharmony_ci----------------------------------------------
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciLinux beats them ALL! While all other OS's are TALKING about direct
58c2ecf20Sopenharmony_cisupport of Java Binaries in the OS, Linux is doing it!
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciYou can execute Java applications and Java Applets just like any
88c2ecf20Sopenharmony_ciother program after you have done the following:
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci1) You MUST FIRST install the Java Developers Kit for Linux.
118c2ecf20Sopenharmony_ci   The Java on Linux HOWTO gives the details on getting and
128c2ecf20Sopenharmony_ci   installing this. This HOWTO can be found at:
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/Java-HOWTO
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci   You should also set up a reasonable CLASSPATH environment
178c2ecf20Sopenharmony_ci   variable to use Java applications that make use of any
188c2ecf20Sopenharmony_ci   nonstandard classes (not included in the same directory
198c2ecf20Sopenharmony_ci   as the application itself).
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci2) You have to compile BINFMT_MISC either as a module or into
228c2ecf20Sopenharmony_ci   the kernel (``CONFIG_BINFMT_MISC``) and set it up properly.
238c2ecf20Sopenharmony_ci   If you choose to compile it as a module, you will have
248c2ecf20Sopenharmony_ci   to insert it manually with modprobe/insmod, as kmod
258c2ecf20Sopenharmony_ci   cannot easily be supported with binfmt_misc.
268c2ecf20Sopenharmony_ci   Read the file 'binfmt_misc.txt' in this directory to know
278c2ecf20Sopenharmony_ci   more about the configuration process.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci3) Add the following configuration items to binfmt_misc
308c2ecf20Sopenharmony_ci   (you should really have read ``binfmt_misc.txt`` now):
318c2ecf20Sopenharmony_ci   support for Java applications::
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci     ':Java:M::\xca\xfe\xba\xbe::/usr/local/bin/javawrapper:'
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci   support for executable Jar files::
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci     ':ExecutableJAR:E::jar::/usr/local/bin/jarwrapper:'
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci   support for Java Applets::
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci     ':Applet:E::html::/usr/bin/appletviewer:'
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci   or the following, if you want to be more selective::
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci     ':Applet:M::<!--applet::/usr/bin/appletviewer:'
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci   Of course you have to fix the path names. The path/file names given in this
488c2ecf20Sopenharmony_ci   document match the Debian 2.1 system. (i.e. jdk installed in ``/usr``,
498c2ecf20Sopenharmony_ci   custom wrappers from this document in ``/usr/local``)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci   Note, that for the more selective applet support you have to modify
528c2ecf20Sopenharmony_ci   existing html-files to contain ``<!--applet-->`` in the first line
538c2ecf20Sopenharmony_ci   (``<`` has to be the first character!) to let this work!
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci   For the compiled Java programs you need a wrapper script like the
568c2ecf20Sopenharmony_ci   following (this is because Java is broken in case of the filename
578c2ecf20Sopenharmony_ci   handling), again fix the path names, both in the script and in the
588c2ecf20Sopenharmony_ci   above given configuration string.
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci   You, too, need the little program after the script. Compile like::
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	gcc -O2 -o javaclassname javaclassname.c
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci   and stick it to ``/usr/local/bin``.
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci   Both the javawrapper shellscript and the javaclassname program
678c2ecf20Sopenharmony_ci   were supplied by Colin J. Watson <cjw44@cam.ac.uk>.
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciJavawrapper shell script:
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci.. code-block:: sh
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci  #!/bin/bash
748c2ecf20Sopenharmony_ci  # /usr/local/bin/javawrapper - the wrapper for binfmt_misc/java
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci  if [ -z "$1" ]; then
778c2ecf20Sopenharmony_ci	exec 1>&2
788c2ecf20Sopenharmony_ci	echo Usage: $0 class-file
798c2ecf20Sopenharmony_ci	exit 1
808c2ecf20Sopenharmony_ci  fi
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci  CLASS=$1
838c2ecf20Sopenharmony_ci  FQCLASS=`/usr/local/bin/javaclassname $1`
848c2ecf20Sopenharmony_ci  FQCLASSN=`echo $FQCLASS | sed -e 's/^.*\.\([^.]*\)$/\1/'`
858c2ecf20Sopenharmony_ci  FQCLASSP=`echo $FQCLASS | sed -e 's-\.-/-g' -e 's-^[^/]*$--' -e 's-/[^/]*$--'`
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci  # for example:
888c2ecf20Sopenharmony_ci  # CLASS=Test.class
898c2ecf20Sopenharmony_ci  # FQCLASS=foo.bar.Test
908c2ecf20Sopenharmony_ci  # FQCLASSN=Test
918c2ecf20Sopenharmony_ci  # FQCLASSP=foo/bar
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci  unset CLASSBASE
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci  declare -i LINKLEVEL=0
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci  while :; do
988c2ecf20Sopenharmony_ci	if [ "`basename $CLASS .class`" == "$FQCLASSN" ]; then
998c2ecf20Sopenharmony_ci		# See if this directory works straight off
1008c2ecf20Sopenharmony_ci		cd -L `dirname $CLASS`
1018c2ecf20Sopenharmony_ci		CLASSDIR=$PWD
1028c2ecf20Sopenharmony_ci		cd $OLDPWD
1038c2ecf20Sopenharmony_ci		if echo $CLASSDIR | grep -q "$FQCLASSP$"; then
1048c2ecf20Sopenharmony_ci			CLASSBASE=`echo $CLASSDIR | sed -e "s.$FQCLASSP$.."`
1058c2ecf20Sopenharmony_ci			break;
1068c2ecf20Sopenharmony_ci		fi
1078c2ecf20Sopenharmony_ci		# Try dereferencing the directory name
1088c2ecf20Sopenharmony_ci		cd -P `dirname $CLASS`
1098c2ecf20Sopenharmony_ci		CLASSDIR=$PWD
1108c2ecf20Sopenharmony_ci		cd $OLDPWD
1118c2ecf20Sopenharmony_ci		if echo $CLASSDIR | grep -q "$FQCLASSP$"; then
1128c2ecf20Sopenharmony_ci			CLASSBASE=`echo $CLASSDIR | sed -e "s.$FQCLASSP$.."`
1138c2ecf20Sopenharmony_ci			break;
1148c2ecf20Sopenharmony_ci		fi
1158c2ecf20Sopenharmony_ci		# If no other possible filename exists
1168c2ecf20Sopenharmony_ci		if [ ! -L $CLASS ]; then
1178c2ecf20Sopenharmony_ci			exec 1>&2
1188c2ecf20Sopenharmony_ci			echo $0:
1198c2ecf20Sopenharmony_ci			echo "  $CLASS should be in a" \
1208c2ecf20Sopenharmony_ci			     "directory tree called $FQCLASSP"
1218c2ecf20Sopenharmony_ci			exit 1
1228c2ecf20Sopenharmony_ci		fi
1238c2ecf20Sopenharmony_ci	fi
1248c2ecf20Sopenharmony_ci	if [ ! -L $CLASS ]; then break; fi
1258c2ecf20Sopenharmony_ci	# Go down one more level of symbolic links
1268c2ecf20Sopenharmony_ci	let LINKLEVEL+=1
1278c2ecf20Sopenharmony_ci	if [ $LINKLEVEL -gt 5 ]; then
1288c2ecf20Sopenharmony_ci		exec 1>&2
1298c2ecf20Sopenharmony_ci		echo $0:
1308c2ecf20Sopenharmony_ci		echo "  Too many symbolic links encountered"
1318c2ecf20Sopenharmony_ci		exit 1
1328c2ecf20Sopenharmony_ci	fi
1338c2ecf20Sopenharmony_ci	CLASS=`ls --color=no -l $CLASS | sed -e 's/^.* \([^ ]*\)$/\1/'`
1348c2ecf20Sopenharmony_ci  done
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci  if [ -z "$CLASSBASE" ]; then
1378c2ecf20Sopenharmony_ci	if [ -z "$FQCLASSP" ]; then
1388c2ecf20Sopenharmony_ci		GOODNAME=$FQCLASSN.class
1398c2ecf20Sopenharmony_ci	else
1408c2ecf20Sopenharmony_ci		GOODNAME=$FQCLASSP/$FQCLASSN.class
1418c2ecf20Sopenharmony_ci	fi
1428c2ecf20Sopenharmony_ci	exec 1>&2
1438c2ecf20Sopenharmony_ci	echo $0:
1448c2ecf20Sopenharmony_ci	echo "  $FQCLASS should be in a file called $GOODNAME"
1458c2ecf20Sopenharmony_ci	exit 1
1468c2ecf20Sopenharmony_ci  fi
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci  if ! echo $CLASSPATH | grep -q "^\(.*:\)*$CLASSBASE\(:.*\)*"; then
1498c2ecf20Sopenharmony_ci	# class is not in CLASSPATH, so prepend dir of class to CLASSPATH
1508c2ecf20Sopenharmony_ci	if [ -z "${CLASSPATH}" ] ; then
1518c2ecf20Sopenharmony_ci		export CLASSPATH=$CLASSBASE
1528c2ecf20Sopenharmony_ci	else
1538c2ecf20Sopenharmony_ci		export CLASSPATH=$CLASSBASE:$CLASSPATH
1548c2ecf20Sopenharmony_ci	fi
1558c2ecf20Sopenharmony_ci  fi
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci  shift
1588c2ecf20Sopenharmony_ci  /usr/bin/java $FQCLASS "$@"
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cijavaclassname.c:
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci.. code-block:: c
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci  /* javaclassname.c
1658c2ecf20Sopenharmony_ci   *
1668c2ecf20Sopenharmony_ci   * Extracts the class name from a Java class file; intended for use in a Java
1678c2ecf20Sopenharmony_ci   * wrapper of the type supported by the binfmt_misc option in the Linux kernel.
1688c2ecf20Sopenharmony_ci   *
1698c2ecf20Sopenharmony_ci   * Copyright (C) 1999 Colin J. Watson <cjw44@cam.ac.uk>.
1708c2ecf20Sopenharmony_ci   *
1718c2ecf20Sopenharmony_ci   * This program is free software; you can redistribute it and/or modify
1728c2ecf20Sopenharmony_ci   * it under the terms of the GNU General Public License as published by
1738c2ecf20Sopenharmony_ci   * the Free Software Foundation; either version 2 of the License, or
1748c2ecf20Sopenharmony_ci   * (at your option) any later version.
1758c2ecf20Sopenharmony_ci   *
1768c2ecf20Sopenharmony_ci   * This program is distributed in the hope that it will be useful,
1778c2ecf20Sopenharmony_ci   * but WITHOUT ANY WARRANTY; without even the implied warranty of
1788c2ecf20Sopenharmony_ci   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1798c2ecf20Sopenharmony_ci   * GNU General Public License for more details.
1808c2ecf20Sopenharmony_ci   *
1818c2ecf20Sopenharmony_ci   * You should have received a copy of the GNU General Public License
1828c2ecf20Sopenharmony_ci   * along with this program; if not, write to the Free Software
1838c2ecf20Sopenharmony_ci   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1848c2ecf20Sopenharmony_ci   */
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci  #include <stdlib.h>
1878c2ecf20Sopenharmony_ci  #include <stdio.h>
1888c2ecf20Sopenharmony_ci  #include <stdarg.h>
1898c2ecf20Sopenharmony_ci  #include <sys/types.h>
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci  /* From Sun's Java VM Specification, as tag entries in the constant pool. */
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci  #define CP_UTF8 1
1948c2ecf20Sopenharmony_ci  #define CP_INTEGER 3
1958c2ecf20Sopenharmony_ci  #define CP_FLOAT 4
1968c2ecf20Sopenharmony_ci  #define CP_LONG 5
1978c2ecf20Sopenharmony_ci  #define CP_DOUBLE 6
1988c2ecf20Sopenharmony_ci  #define CP_CLASS 7
1998c2ecf20Sopenharmony_ci  #define CP_STRING 8
2008c2ecf20Sopenharmony_ci  #define CP_FIELDREF 9
2018c2ecf20Sopenharmony_ci  #define CP_METHODREF 10
2028c2ecf20Sopenharmony_ci  #define CP_INTERFACEMETHODREF 11
2038c2ecf20Sopenharmony_ci  #define CP_NAMEANDTYPE 12
2048c2ecf20Sopenharmony_ci  #define CP_METHODHANDLE 15
2058c2ecf20Sopenharmony_ci  #define CP_METHODTYPE 16
2068c2ecf20Sopenharmony_ci  #define CP_INVOKEDYNAMIC 18
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci  /* Define some commonly used error messages */
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci  #define seek_error() error("%s: Cannot seek\n", program)
2118c2ecf20Sopenharmony_ci  #define corrupt_error() error("%s: Class file corrupt\n", program)
2128c2ecf20Sopenharmony_ci  #define eof_error() error("%s: Unexpected end of file\n", program)
2138c2ecf20Sopenharmony_ci  #define utf8_error() error("%s: Only ASCII 1-255 supported\n", program);
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci  char *program;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci  long *pool;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci  u_int8_t read_8(FILE *classfile);
2208c2ecf20Sopenharmony_ci  u_int16_t read_16(FILE *classfile);
2218c2ecf20Sopenharmony_ci  void skip_constant(FILE *classfile, u_int16_t *cur);
2228c2ecf20Sopenharmony_ci  void error(const char *format, ...);
2238c2ecf20Sopenharmony_ci  int main(int argc, char **argv);
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci  /* Reads in an unsigned 8-bit integer. */
2268c2ecf20Sopenharmony_ci  u_int8_t read_8(FILE *classfile)
2278c2ecf20Sopenharmony_ci  {
2288c2ecf20Sopenharmony_ci	int b = fgetc(classfile);
2298c2ecf20Sopenharmony_ci	if(b == EOF)
2308c2ecf20Sopenharmony_ci		eof_error();
2318c2ecf20Sopenharmony_ci	return (u_int8_t)b;
2328c2ecf20Sopenharmony_ci  }
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci  /* Reads in an unsigned 16-bit integer. */
2358c2ecf20Sopenharmony_ci  u_int16_t read_16(FILE *classfile)
2368c2ecf20Sopenharmony_ci  {
2378c2ecf20Sopenharmony_ci	int b1, b2;
2388c2ecf20Sopenharmony_ci	b1 = fgetc(classfile);
2398c2ecf20Sopenharmony_ci	if(b1 == EOF)
2408c2ecf20Sopenharmony_ci		eof_error();
2418c2ecf20Sopenharmony_ci	b2 = fgetc(classfile);
2428c2ecf20Sopenharmony_ci	if(b2 == EOF)
2438c2ecf20Sopenharmony_ci		eof_error();
2448c2ecf20Sopenharmony_ci	return (u_int16_t)((b1 << 8) | b2);
2458c2ecf20Sopenharmony_ci  }
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci  /* Reads in a value from the constant pool. */
2488c2ecf20Sopenharmony_ci  void skip_constant(FILE *classfile, u_int16_t *cur)
2498c2ecf20Sopenharmony_ci  {
2508c2ecf20Sopenharmony_ci	u_int16_t len;
2518c2ecf20Sopenharmony_ci	int seekerr = 1;
2528c2ecf20Sopenharmony_ci	pool[*cur] = ftell(classfile);
2538c2ecf20Sopenharmony_ci	switch(read_8(classfile))
2548c2ecf20Sopenharmony_ci	{
2558c2ecf20Sopenharmony_ci	case CP_UTF8:
2568c2ecf20Sopenharmony_ci		len = read_16(classfile);
2578c2ecf20Sopenharmony_ci		seekerr = fseek(classfile, len, SEEK_CUR);
2588c2ecf20Sopenharmony_ci		break;
2598c2ecf20Sopenharmony_ci	case CP_CLASS:
2608c2ecf20Sopenharmony_ci	case CP_STRING:
2618c2ecf20Sopenharmony_ci	case CP_METHODTYPE:
2628c2ecf20Sopenharmony_ci		seekerr = fseek(classfile, 2, SEEK_CUR);
2638c2ecf20Sopenharmony_ci		break;
2648c2ecf20Sopenharmony_ci	case CP_METHODHANDLE:
2658c2ecf20Sopenharmony_ci		seekerr = fseek(classfile, 3, SEEK_CUR);
2668c2ecf20Sopenharmony_ci		break;
2678c2ecf20Sopenharmony_ci	case CP_INTEGER:
2688c2ecf20Sopenharmony_ci	case CP_FLOAT:
2698c2ecf20Sopenharmony_ci	case CP_FIELDREF:
2708c2ecf20Sopenharmony_ci	case CP_METHODREF:
2718c2ecf20Sopenharmony_ci	case CP_INTERFACEMETHODREF:
2728c2ecf20Sopenharmony_ci	case CP_NAMEANDTYPE:
2738c2ecf20Sopenharmony_ci	case CP_INVOKEDYNAMIC:
2748c2ecf20Sopenharmony_ci		seekerr = fseek(classfile, 4, SEEK_CUR);
2758c2ecf20Sopenharmony_ci		break;
2768c2ecf20Sopenharmony_ci	case CP_LONG:
2778c2ecf20Sopenharmony_ci	case CP_DOUBLE:
2788c2ecf20Sopenharmony_ci		seekerr = fseek(classfile, 8, SEEK_CUR);
2798c2ecf20Sopenharmony_ci		++(*cur);
2808c2ecf20Sopenharmony_ci		break;
2818c2ecf20Sopenharmony_ci	default:
2828c2ecf20Sopenharmony_ci		corrupt_error();
2838c2ecf20Sopenharmony_ci	}
2848c2ecf20Sopenharmony_ci	if(seekerr)
2858c2ecf20Sopenharmony_ci		seek_error();
2868c2ecf20Sopenharmony_ci  }
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci  void error(const char *format, ...)
2898c2ecf20Sopenharmony_ci  {
2908c2ecf20Sopenharmony_ci	va_list ap;
2918c2ecf20Sopenharmony_ci	va_start(ap, format);
2928c2ecf20Sopenharmony_ci	vfprintf(stderr, format, ap);
2938c2ecf20Sopenharmony_ci	va_end(ap);
2948c2ecf20Sopenharmony_ci	exit(1);
2958c2ecf20Sopenharmony_ci  }
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci  int main(int argc, char **argv)
2988c2ecf20Sopenharmony_ci  {
2998c2ecf20Sopenharmony_ci	FILE *classfile;
3008c2ecf20Sopenharmony_ci	u_int16_t cp_count, i, this_class, classinfo_ptr;
3018c2ecf20Sopenharmony_ci	u_int8_t length;
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	program = argv[0];
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	if(!argv[1])
3068c2ecf20Sopenharmony_ci		error("%s: Missing input file\n", program);
3078c2ecf20Sopenharmony_ci	classfile = fopen(argv[1], "rb");
3088c2ecf20Sopenharmony_ci	if(!classfile)
3098c2ecf20Sopenharmony_ci		error("%s: Error opening %s\n", program, argv[1]);
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	if(fseek(classfile, 8, SEEK_SET))  /* skip magic and version numbers */
3128c2ecf20Sopenharmony_ci		seek_error();
3138c2ecf20Sopenharmony_ci	cp_count = read_16(classfile);
3148c2ecf20Sopenharmony_ci	pool = calloc(cp_count, sizeof(long));
3158c2ecf20Sopenharmony_ci	if(!pool)
3168c2ecf20Sopenharmony_ci		error("%s: Out of memory for constant pool\n", program);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	for(i = 1; i < cp_count; ++i)
3198c2ecf20Sopenharmony_ci		skip_constant(classfile, &i);
3208c2ecf20Sopenharmony_ci	if(fseek(classfile, 2, SEEK_CUR))	/* skip access flags */
3218c2ecf20Sopenharmony_ci		seek_error();
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	this_class = read_16(classfile);
3248c2ecf20Sopenharmony_ci	if(this_class < 1 || this_class >= cp_count)
3258c2ecf20Sopenharmony_ci		corrupt_error();
3268c2ecf20Sopenharmony_ci	if(!pool[this_class] || pool[this_class] == -1)
3278c2ecf20Sopenharmony_ci		corrupt_error();
3288c2ecf20Sopenharmony_ci	if(fseek(classfile, pool[this_class] + 1, SEEK_SET))
3298c2ecf20Sopenharmony_ci		seek_error();
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	classinfo_ptr = read_16(classfile);
3328c2ecf20Sopenharmony_ci	if(classinfo_ptr < 1 || classinfo_ptr >= cp_count)
3338c2ecf20Sopenharmony_ci		corrupt_error();
3348c2ecf20Sopenharmony_ci	if(!pool[classinfo_ptr] || pool[classinfo_ptr] == -1)
3358c2ecf20Sopenharmony_ci		corrupt_error();
3368c2ecf20Sopenharmony_ci	if(fseek(classfile, pool[classinfo_ptr] + 1, SEEK_SET))
3378c2ecf20Sopenharmony_ci		seek_error();
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	length = read_16(classfile);
3408c2ecf20Sopenharmony_ci	for(i = 0; i < length; ++i)
3418c2ecf20Sopenharmony_ci	{
3428c2ecf20Sopenharmony_ci		u_int8_t x = read_8(classfile);
3438c2ecf20Sopenharmony_ci		if((x & 0x80) || !x)
3448c2ecf20Sopenharmony_ci		{
3458c2ecf20Sopenharmony_ci			if((x & 0xE0) == 0xC0)
3468c2ecf20Sopenharmony_ci			{
3478c2ecf20Sopenharmony_ci				u_int8_t y = read_8(classfile);
3488c2ecf20Sopenharmony_ci				if((y & 0xC0) == 0x80)
3498c2ecf20Sopenharmony_ci				{
3508c2ecf20Sopenharmony_ci					int c = ((x & 0x1f) << 6) + (y & 0x3f);
3518c2ecf20Sopenharmony_ci					if(c) putchar(c);
3528c2ecf20Sopenharmony_ci					else utf8_error();
3538c2ecf20Sopenharmony_ci				}
3548c2ecf20Sopenharmony_ci				else utf8_error();
3558c2ecf20Sopenharmony_ci			}
3568c2ecf20Sopenharmony_ci			else utf8_error();
3578c2ecf20Sopenharmony_ci		}
3588c2ecf20Sopenharmony_ci		else if(x == '/') putchar('.');
3598c2ecf20Sopenharmony_ci		else putchar(x);
3608c2ecf20Sopenharmony_ci	}
3618c2ecf20Sopenharmony_ci	putchar('\n');
3628c2ecf20Sopenharmony_ci	free(pool);
3638c2ecf20Sopenharmony_ci	fclose(classfile);
3648c2ecf20Sopenharmony_ci	return 0;
3658c2ecf20Sopenharmony_ci  }
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_cijarwrapper::
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci  #!/bin/bash
3708c2ecf20Sopenharmony_ci  # /usr/local/java/bin/jarwrapper - the wrapper for binfmt_misc/jar
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci  java -jar $1
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ciNow simply ``chmod +x`` the ``.class``, ``.jar`` and/or ``.html`` files you
3768c2ecf20Sopenharmony_ciwant to execute.
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ciTo add a Java program to your path best put a symbolic link to the main
3798c2ecf20Sopenharmony_ci.class file into /usr/bin (or another place you like) omitting the .class
3808c2ecf20Sopenharmony_ciextension. The directory containing the original .class file will be
3818c2ecf20Sopenharmony_ciadded to your CLASSPATH during execution.
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ciTo test your new setup, enter in the following simple Java app, and name
3858c2ecf20Sopenharmony_ciit "HelloWorld.java":
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci.. code-block:: java
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	class HelloWorld {
3908c2ecf20Sopenharmony_ci		public static void main(String args[]) {
3918c2ecf20Sopenharmony_ci			System.out.println("Hello World!");
3928c2ecf20Sopenharmony_ci		}
3938c2ecf20Sopenharmony_ci	}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ciNow compile the application with::
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	javac HelloWorld.java
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ciSet the executable permissions of the binary file, with::
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	chmod 755 HelloWorld.class
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ciAnd then execute it::
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	./HelloWorld.class
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ciTo execute Java Jar files, simple chmod the ``*.jar`` files to include
4098c2ecf20Sopenharmony_cithe execution bit, then just do::
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci       ./Application.jar
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ciTo execute Java Applets, simple chmod the ``*.html`` files to include
4158c2ecf20Sopenharmony_cithe execution bit, then just do::
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci	./Applet.html
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_cioriginally by Brian A. Lantz, brian@lantz.com
4218c2ecf20Sopenharmony_ciheavily edited for binfmt_misc by Richard Günther
4228c2ecf20Sopenharmony_cinew scripts by Colin J. Watson <cjw44@cam.ac.uk>
4238c2ecf20Sopenharmony_ciadded executable Jar file support by Kurt Huwig <kurt@iku-netz.de>
424