ia64/linux-2.6.18-xen.hg

annotate Documentation/java.txt @ 524:7f8b544237bf

netfront: Allow netfront in domain 0.

This is useful if your physical network device is in a utility domain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 15 15:18:58 2008 +0100 (2008-04-15)
parents 831230e53067
children
rev   line source
ian@0 1 Java(tm) Binary Kernel Support for Linux v1.03
ian@0 2 ----------------------------------------------
ian@0 3
ian@0 4 Linux beats them ALL! While all other OS's are TALKING about direct
ian@0 5 support of Java Binaries in the OS, Linux is doing it!
ian@0 6
ian@0 7 You can execute Java applications and Java Applets just like any
ian@0 8 other program after you have done the following:
ian@0 9
ian@0 10 1) You MUST FIRST install the Java Developers Kit for Linux.
ian@0 11 The Java on Linux HOWTO gives the details on getting and
ian@0 12 installing this. This HOWTO can be found at:
ian@0 13
ian@0 14 ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/Java-HOWTO
ian@0 15
ian@0 16 You should also set up a reasonable CLASSPATH environment
ian@0 17 variable to use Java applications that make use of any
ian@0 18 nonstandard classes (not included in the same directory
ian@0 19 as the application itself).
ian@0 20
ian@0 21 2) You have to compile BINFMT_MISC either as a module or into
ian@0 22 the kernel (CONFIG_BINFMT_MISC) and set it up properly.
ian@0 23 If you choose to compile it as a module, you will have
ian@0 24 to insert it manually with modprobe/insmod, as kmod
ian@0 25 can not easily be supported with binfmt_misc.
ian@0 26 Read the file 'binfmt_misc.txt' in this directory to know
ian@0 27 more about the configuration process.
ian@0 28
ian@0 29 3) Add the following configuration items to binfmt_misc
ian@0 30 (you should really have read binfmt_misc.txt now):
ian@0 31 support for Java applications:
ian@0 32 ':Java:M::\xca\xfe\xba\xbe::/usr/local/bin/javawrapper:'
ian@0 33 support for executable Jar files:
ian@0 34 ':ExecutableJAR:E::jar::/usr/local/bin/jarwrapper:'
ian@0 35 support for Java Applets:
ian@0 36 ':Applet:E::html::/usr/bin/appletviewer:'
ian@0 37 or the following, if you want to be more selective:
ian@0 38 ':Applet:M::<!--applet::/usr/bin/appletviewer:'
ian@0 39
ian@0 40 Of cause you have to fix the path names. Given path/file names in this
ian@0 41 document match the Debian 2.1 system. (i.e. jdk installed in /usr,
ian@0 42 custom wrappers from this document in /usr/local)
ian@0 43
ian@0 44 Note, that for the more selective applet support you have to modify
ian@0 45 existing html-files to contain <!--applet--> in the first line
ian@0 46 ('<' has to be the first character!) to let this work!
ian@0 47
ian@0 48 For the compiled Java programs you need a wrapper script like the
ian@0 49 following (this is because Java is broken in case of the filename
ian@0 50 handling), again fix the path names, both in the script and in the
ian@0 51 above given configuration string.
ian@0 52
ian@0 53 You, too, need the little program after the script. Compile like
ian@0 54 gcc -O2 -o javaclassname javaclassname.c
ian@0 55 and stick it to /usr/local/bin.
ian@0 56
ian@0 57 Both the javawrapper shellscript and the javaclassname program
ian@0 58 were supplied by Colin J. Watson <cjw44@cam.ac.uk>.
ian@0 59
ian@0 60 ====================== Cut here ===================
ian@0 61 #!/bin/bash
ian@0 62 # /usr/local/bin/javawrapper - the wrapper for binfmt_misc/java
ian@0 63
ian@0 64 if [ -z "$1" ]; then
ian@0 65 exec 1>&2
ian@0 66 echo Usage: $0 class-file
ian@0 67 exit 1
ian@0 68 fi
ian@0 69
ian@0 70 CLASS=$1
ian@0 71 FQCLASS=`/usr/local/bin/javaclassname $1`
ian@0 72 FQCLASSN=`echo $FQCLASS | sed -e 's/^.*\.\([^.]*\)$/\1/'`
ian@0 73 FQCLASSP=`echo $FQCLASS | sed -e 's-\.-/-g' -e 's-^[^/]*$--' -e 's-/[^/]*$--'`
ian@0 74
ian@0 75 # for example:
ian@0 76 # CLASS=Test.class
ian@0 77 # FQCLASS=foo.bar.Test
ian@0 78 # FQCLASSN=Test
ian@0 79 # FQCLASSP=foo/bar
ian@0 80
ian@0 81 unset CLASSBASE
ian@0 82
ian@0 83 declare -i LINKLEVEL=0
ian@0 84
ian@0 85 while :; do
ian@0 86 if [ "`basename $CLASS .class`" == "$FQCLASSN" ]; then
ian@0 87 # See if this directory works straight off
ian@0 88 cd -L `dirname $CLASS`
ian@0 89 CLASSDIR=$PWD
ian@0 90 cd $OLDPWD
ian@0 91 if echo $CLASSDIR | grep -q "$FQCLASSP$"; then
ian@0 92 CLASSBASE=`echo $CLASSDIR | sed -e "s.$FQCLASSP$.."`
ian@0 93 break;
ian@0 94 fi
ian@0 95 # Try dereferencing the directory name
ian@0 96 cd -P `dirname $CLASS`
ian@0 97 CLASSDIR=$PWD
ian@0 98 cd $OLDPWD
ian@0 99 if echo $CLASSDIR | grep -q "$FQCLASSP$"; then
ian@0 100 CLASSBASE=`echo $CLASSDIR | sed -e "s.$FQCLASSP$.."`
ian@0 101 break;
ian@0 102 fi
ian@0 103 # If no other possible filename exists
ian@0 104 if [ ! -L $CLASS ]; then
ian@0 105 exec 1>&2
ian@0 106 echo $0:
ian@0 107 echo " $CLASS should be in a" \
ian@0 108 "directory tree called $FQCLASSP"
ian@0 109 exit 1
ian@0 110 fi
ian@0 111 fi
ian@0 112 if [ ! -L $CLASS ]; then break; fi
ian@0 113 # Go down one more level of symbolic links
ian@0 114 let LINKLEVEL+=1
ian@0 115 if [ $LINKLEVEL -gt 5 ]; then
ian@0 116 exec 1>&2
ian@0 117 echo $0:
ian@0 118 echo " Too many symbolic links encountered"
ian@0 119 exit 1
ian@0 120 fi
ian@0 121 CLASS=`ls --color=no -l $CLASS | sed -e 's/^.* \([^ ]*\)$/\1/'`
ian@0 122 done
ian@0 123
ian@0 124 if [ -z "$CLASSBASE" ]; then
ian@0 125 if [ -z "$FQCLASSP" ]; then
ian@0 126 GOODNAME=$FQCLASSN.class
ian@0 127 else
ian@0 128 GOODNAME=$FQCLASSP/$FQCLASSN.class
ian@0 129 fi
ian@0 130 exec 1>&2
ian@0 131 echo $0:
ian@0 132 echo " $FQCLASS should be in a file called $GOODNAME"
ian@0 133 exit 1
ian@0 134 fi
ian@0 135
ian@0 136 if ! echo $CLASSPATH | grep -q "^\(.*:\)*$CLASSBASE\(:.*\)*"; then
ian@0 137 # class is not in CLASSPATH, so prepend dir of class to CLASSPATH
ian@0 138 if [ -z "${CLASSPATH}" ] ; then
ian@0 139 export CLASSPATH=$CLASSBASE
ian@0 140 else
ian@0 141 export CLASSPATH=$CLASSBASE:$CLASSPATH
ian@0 142 fi
ian@0 143 fi
ian@0 144
ian@0 145 shift
ian@0 146 /usr/bin/java $FQCLASS "$@"
ian@0 147 ====================== Cut here ===================
ian@0 148
ian@0 149
ian@0 150 ====================== Cut here ===================
ian@0 151 /* javaclassname.c
ian@0 152 *
ian@0 153 * Extracts the class name from a Java class file; intended for use in a Java
ian@0 154 * wrapper of the type supported by the binfmt_misc option in the Linux kernel.
ian@0 155 *
ian@0 156 * Copyright (C) 1999 Colin J. Watson <cjw44@cam.ac.uk>.
ian@0 157 *
ian@0 158 * This program is free software; you can redistribute it and/or modify
ian@0 159 * it under the terms of the GNU General Public License as published by
ian@0 160 * the Free Software Foundation; either version 2 of the License, or
ian@0 161 * (at your option) any later version.
ian@0 162 *
ian@0 163 * This program is distributed in the hope that it will be useful,
ian@0 164 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 165 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ian@0 166 * GNU General Public License for more details.
ian@0 167 *
ian@0 168 * You should have received a copy of the GNU General Public License
ian@0 169 * along with this program; if not, write to the Free Software
ian@0 170 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ian@0 171 */
ian@0 172
ian@0 173 #include <stdlib.h>
ian@0 174 #include <stdio.h>
ian@0 175 #include <stdarg.h>
ian@0 176 #include <sys/types.h>
ian@0 177
ian@0 178 /* From Sun's Java VM Specification, as tag entries in the constant pool. */
ian@0 179
ian@0 180 #define CP_UTF8 1
ian@0 181 #define CP_INTEGER 3
ian@0 182 #define CP_FLOAT 4
ian@0 183 #define CP_LONG 5
ian@0 184 #define CP_DOUBLE 6
ian@0 185 #define CP_CLASS 7
ian@0 186 #define CP_STRING 8
ian@0 187 #define CP_FIELDREF 9
ian@0 188 #define CP_METHODREF 10
ian@0 189 #define CP_INTERFACEMETHODREF 11
ian@0 190 #define CP_NAMEANDTYPE 12
ian@0 191
ian@0 192 /* Define some commonly used error messages */
ian@0 193
ian@0 194 #define seek_error() error("%s: Cannot seek\n", program)
ian@0 195 #define corrupt_error() error("%s: Class file corrupt\n", program)
ian@0 196 #define eof_error() error("%s: Unexpected end of file\n", program)
ian@0 197 #define utf8_error() error("%s: Only ASCII 1-255 supported\n", program);
ian@0 198
ian@0 199 char *program;
ian@0 200
ian@0 201 long *pool;
ian@0 202
ian@0 203 u_int8_t read_8(FILE *classfile);
ian@0 204 u_int16_t read_16(FILE *classfile);
ian@0 205 void skip_constant(FILE *classfile, u_int16_t *cur);
ian@0 206 void error(const char *format, ...);
ian@0 207 int main(int argc, char **argv);
ian@0 208
ian@0 209 /* Reads in an unsigned 8-bit integer. */
ian@0 210 u_int8_t read_8(FILE *classfile)
ian@0 211 {
ian@0 212 int b = fgetc(classfile);
ian@0 213 if(b == EOF)
ian@0 214 eof_error();
ian@0 215 return (u_int8_t)b;
ian@0 216 }
ian@0 217
ian@0 218 /* Reads in an unsigned 16-bit integer. */
ian@0 219 u_int16_t read_16(FILE *classfile)
ian@0 220 {
ian@0 221 int b1, b2;
ian@0 222 b1 = fgetc(classfile);
ian@0 223 if(b1 == EOF)
ian@0 224 eof_error();
ian@0 225 b2 = fgetc(classfile);
ian@0 226 if(b2 == EOF)
ian@0 227 eof_error();
ian@0 228 return (u_int16_t)((b1 << 8) | b2);
ian@0 229 }
ian@0 230
ian@0 231 /* Reads in a value from the constant pool. */
ian@0 232 void skip_constant(FILE *classfile, u_int16_t *cur)
ian@0 233 {
ian@0 234 u_int16_t len;
ian@0 235 int seekerr = 1;
ian@0 236 pool[*cur] = ftell(classfile);
ian@0 237 switch(read_8(classfile))
ian@0 238 {
ian@0 239 case CP_UTF8:
ian@0 240 len = read_16(classfile);
ian@0 241 seekerr = fseek(classfile, len, SEEK_CUR);
ian@0 242 break;
ian@0 243 case CP_CLASS:
ian@0 244 case CP_STRING:
ian@0 245 seekerr = fseek(classfile, 2, SEEK_CUR);
ian@0 246 break;
ian@0 247 case CP_INTEGER:
ian@0 248 case CP_FLOAT:
ian@0 249 case CP_FIELDREF:
ian@0 250 case CP_METHODREF:
ian@0 251 case CP_INTERFACEMETHODREF:
ian@0 252 case CP_NAMEANDTYPE:
ian@0 253 seekerr = fseek(classfile, 4, SEEK_CUR);
ian@0 254 break;
ian@0 255 case CP_LONG:
ian@0 256 case CP_DOUBLE:
ian@0 257 seekerr = fseek(classfile, 8, SEEK_CUR);
ian@0 258 ++(*cur);
ian@0 259 break;
ian@0 260 default:
ian@0 261 corrupt_error();
ian@0 262 }
ian@0 263 if(seekerr)
ian@0 264 seek_error();
ian@0 265 }
ian@0 266
ian@0 267 void error(const char *format, ...)
ian@0 268 {
ian@0 269 va_list ap;
ian@0 270 va_start(ap, format);
ian@0 271 vfprintf(stderr, format, ap);
ian@0 272 va_end(ap);
ian@0 273 exit(1);
ian@0 274 }
ian@0 275
ian@0 276 int main(int argc, char **argv)
ian@0 277 {
ian@0 278 FILE *classfile;
ian@0 279 u_int16_t cp_count, i, this_class, classinfo_ptr;
ian@0 280 u_int8_t length;
ian@0 281
ian@0 282 program = argv[0];
ian@0 283
ian@0 284 if(!argv[1])
ian@0 285 error("%s: Missing input file\n", program);
ian@0 286 classfile = fopen(argv[1], "rb");
ian@0 287 if(!classfile)
ian@0 288 error("%s: Error opening %s\n", program, argv[1]);
ian@0 289
ian@0 290 if(fseek(classfile, 8, SEEK_SET)) /* skip magic and version numbers */
ian@0 291 seek_error();
ian@0 292 cp_count = read_16(classfile);
ian@0 293 pool = calloc(cp_count, sizeof(long));
ian@0 294 if(!pool)
ian@0 295 error("%s: Out of memory for constant pool\n", program);
ian@0 296
ian@0 297 for(i = 1; i < cp_count; ++i)
ian@0 298 skip_constant(classfile, &i);
ian@0 299 if(fseek(classfile, 2, SEEK_CUR)) /* skip access flags */
ian@0 300 seek_error();
ian@0 301
ian@0 302 this_class = read_16(classfile);
ian@0 303 if(this_class < 1 || this_class >= cp_count)
ian@0 304 corrupt_error();
ian@0 305 if(!pool[this_class] || pool[this_class] == -1)
ian@0 306 corrupt_error();
ian@0 307 if(fseek(classfile, pool[this_class] + 1, SEEK_SET))
ian@0 308 seek_error();
ian@0 309
ian@0 310 classinfo_ptr = read_16(classfile);
ian@0 311 if(classinfo_ptr < 1 || classinfo_ptr >= cp_count)
ian@0 312 corrupt_error();
ian@0 313 if(!pool[classinfo_ptr] || pool[classinfo_ptr] == -1)
ian@0 314 corrupt_error();
ian@0 315 if(fseek(classfile, pool[classinfo_ptr] + 1, SEEK_SET))
ian@0 316 seek_error();
ian@0 317
ian@0 318 length = read_16(classfile);
ian@0 319 for(i = 0; i < length; ++i)
ian@0 320 {
ian@0 321 u_int8_t x = read_8(classfile);
ian@0 322 if((x & 0x80) || !x)
ian@0 323 {
ian@0 324 if((x & 0xE0) == 0xC0)
ian@0 325 {
ian@0 326 u_int8_t y = read_8(classfile);
ian@0 327 if((y & 0xC0) == 0x80)
ian@0 328 {
ian@0 329 int c = ((x & 0x1f) << 6) + (y & 0x3f);
ian@0 330 if(c) putchar(c);
ian@0 331 else utf8_error();
ian@0 332 }
ian@0 333 else utf8_error();
ian@0 334 }
ian@0 335 else utf8_error();
ian@0 336 }
ian@0 337 else if(x == '/') putchar('.');
ian@0 338 else putchar(x);
ian@0 339 }
ian@0 340 putchar('\n');
ian@0 341 free(pool);
ian@0 342 fclose(classfile);
ian@0 343 return 0;
ian@0 344 }
ian@0 345 ====================== Cut here ===================
ian@0 346
ian@0 347
ian@0 348 ====================== Cut here ===================
ian@0 349 #!/bin/bash
ian@0 350 # /usr/local/java/bin/jarwrapper - the wrapper for binfmt_misc/jar
ian@0 351
ian@0 352 java -jar $1
ian@0 353 ====================== Cut here ===================
ian@0 354
ian@0 355
ian@0 356 Now simply chmod +x the .class, .jar and/or .html files you want to execute.
ian@0 357 To add a Java program to your path best put a symbolic link to the main
ian@0 358 .class file into /usr/bin (or another place you like) omitting the .class
ian@0 359 extension. The directory containing the original .class file will be
ian@0 360 added to your CLASSPATH during execution.
ian@0 361
ian@0 362
ian@0 363 To test your new setup, enter in the following simple Java app, and name
ian@0 364 it "HelloWorld.java":
ian@0 365
ian@0 366 class HelloWorld {
ian@0 367 public static void main(String args[]) {
ian@0 368 System.out.println("Hello World!");
ian@0 369 }
ian@0 370 }
ian@0 371
ian@0 372 Now compile the application with:
ian@0 373 javac HelloWorld.java
ian@0 374
ian@0 375 Set the executable permissions of the binary file, with:
ian@0 376 chmod 755 HelloWorld.class
ian@0 377
ian@0 378 And then execute it:
ian@0 379 ./HelloWorld.class
ian@0 380
ian@0 381
ian@0 382 To execute Java Jar files, simple chmod the *.jar files to include
ian@0 383 the execution bit, then just do
ian@0 384 ./Application.jar
ian@0 385
ian@0 386
ian@0 387 To execute Java Applets, simple chmod the *.html files to include
ian@0 388 the execution bit, then just do
ian@0 389 ./Applet.html
ian@0 390
ian@0 391
ian@0 392 originally by Brian A. Lantz, brian@lantz.com
ian@0 393 heavily edited for binfmt_misc by Richard GŁnther
ian@0 394 new scripts by Colin J. Watson <cjw44@cam.ac.uk>
ian@0 395 added executable Jar file support by Kurt Huwig <kurt@iku-netz.de>
ian@0 396