162306a36Sopenharmony_ciJava(tm) Binary Kernel Support for Linux v1.03 262306a36Sopenharmony_ci---------------------------------------------- 362306a36Sopenharmony_ci 462306a36Sopenharmony_ciLinux beats them ALL! While all other OS's are TALKING about direct 562306a36Sopenharmony_cisupport of Java Binaries in the OS, Linux is doing it! 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciYou can execute Java applications and Java Applets just like any 862306a36Sopenharmony_ciother program after you have done the following: 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci1) You MUST FIRST install the Java Developers Kit for Linux. 1162306a36Sopenharmony_ci The Java on Linux HOWTO gives the details on getting and 1262306a36Sopenharmony_ci installing this. This HOWTO can be found at: 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/Java-HOWTO 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci You should also set up a reasonable CLASSPATH environment 1762306a36Sopenharmony_ci variable to use Java applications that make use of any 1862306a36Sopenharmony_ci nonstandard classes (not included in the same directory 1962306a36Sopenharmony_ci as the application itself). 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci2) You have to compile BINFMT_MISC either as a module or into 2262306a36Sopenharmony_ci the kernel (``CONFIG_BINFMT_MISC``) and set it up properly. 2362306a36Sopenharmony_ci If you choose to compile it as a module, you will have 2462306a36Sopenharmony_ci to insert it manually with modprobe/insmod, as kmod 2562306a36Sopenharmony_ci cannot easily be supported with binfmt_misc. 2662306a36Sopenharmony_ci Read the file 'binfmt_misc.txt' in this directory to know 2762306a36Sopenharmony_ci more about the configuration process. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci3) Add the following configuration items to binfmt_misc 3062306a36Sopenharmony_ci (you should really have read ``binfmt_misc.txt`` now): 3162306a36Sopenharmony_ci support for Java applications:: 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci ':Java:M::\xca\xfe\xba\xbe::/usr/local/bin/javawrapper:' 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci support for executable Jar files:: 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci ':ExecutableJAR:E::jar::/usr/local/bin/jarwrapper:' 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci support for Java Applets:: 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci ':Applet:E::html::/usr/bin/appletviewer:' 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci or the following, if you want to be more selective:: 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci ':Applet:M::<!--applet::/usr/bin/appletviewer:' 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci Of course you have to fix the path names. The path/file names given in this 4862306a36Sopenharmony_ci document match the Debian 2.1 system. (i.e. jdk installed in ``/usr``, 4962306a36Sopenharmony_ci custom wrappers from this document in ``/usr/local``) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci Note, that for the more selective applet support you have to modify 5262306a36Sopenharmony_ci existing html-files to contain ``<!--applet-->`` in the first line 5362306a36Sopenharmony_ci (``<`` has to be the first character!) to let this work! 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci For the compiled Java programs you need a wrapper script like the 5662306a36Sopenharmony_ci following (this is because Java is broken in case of the filename 5762306a36Sopenharmony_ci handling), again fix the path names, both in the script and in the 5862306a36Sopenharmony_ci above given configuration string. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci You, too, need the little program after the script. Compile like:: 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci gcc -O2 -o javaclassname javaclassname.c 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci and stick it to ``/usr/local/bin``. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci Both the javawrapper shellscript and the javaclassname program 6762306a36Sopenharmony_ci were supplied by Colin J. Watson <cjw44@cam.ac.uk>. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciJavawrapper shell script: 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci.. code-block:: sh 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci #!/bin/bash 7462306a36Sopenharmony_ci # /usr/local/bin/javawrapper - the wrapper for binfmt_misc/java 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci if [ -z "$1" ]; then 7762306a36Sopenharmony_ci exec 1>&2 7862306a36Sopenharmony_ci echo Usage: $0 class-file 7962306a36Sopenharmony_ci exit 1 8062306a36Sopenharmony_ci fi 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci CLASS=$1 8362306a36Sopenharmony_ci FQCLASS=`/usr/local/bin/javaclassname $1` 8462306a36Sopenharmony_ci FQCLASSN=`echo $FQCLASS | sed -e 's/^.*\.\([^.]*\)$/\1/'` 8562306a36Sopenharmony_ci FQCLASSP=`echo $FQCLASS | sed -e 's-\.-/-g' -e 's-^[^/]*$--' -e 's-/[^/]*$--'` 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci # for example: 8862306a36Sopenharmony_ci # CLASS=Test.class 8962306a36Sopenharmony_ci # FQCLASS=foo.bar.Test 9062306a36Sopenharmony_ci # FQCLASSN=Test 9162306a36Sopenharmony_ci # FQCLASSP=foo/bar 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci unset CLASSBASE 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci declare -i LINKLEVEL=0 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci while :; do 9862306a36Sopenharmony_ci if [ "`basename $CLASS .class`" == "$FQCLASSN" ]; then 9962306a36Sopenharmony_ci # See if this directory works straight off 10062306a36Sopenharmony_ci cd -L `dirname $CLASS` 10162306a36Sopenharmony_ci CLASSDIR=$PWD 10262306a36Sopenharmony_ci cd $OLDPWD 10362306a36Sopenharmony_ci if echo $CLASSDIR | grep -q "$FQCLASSP$"; then 10462306a36Sopenharmony_ci CLASSBASE=`echo $CLASSDIR | sed -e "s.$FQCLASSP$.."` 10562306a36Sopenharmony_ci break; 10662306a36Sopenharmony_ci fi 10762306a36Sopenharmony_ci # Try dereferencing the directory name 10862306a36Sopenharmony_ci cd -P `dirname $CLASS` 10962306a36Sopenharmony_ci CLASSDIR=$PWD 11062306a36Sopenharmony_ci cd $OLDPWD 11162306a36Sopenharmony_ci if echo $CLASSDIR | grep -q "$FQCLASSP$"; then 11262306a36Sopenharmony_ci CLASSBASE=`echo $CLASSDIR | sed -e "s.$FQCLASSP$.."` 11362306a36Sopenharmony_ci break; 11462306a36Sopenharmony_ci fi 11562306a36Sopenharmony_ci # If no other possible filename exists 11662306a36Sopenharmony_ci if [ ! -L $CLASS ]; then 11762306a36Sopenharmony_ci exec 1>&2 11862306a36Sopenharmony_ci echo $0: 11962306a36Sopenharmony_ci echo " $CLASS should be in a" \ 12062306a36Sopenharmony_ci "directory tree called $FQCLASSP" 12162306a36Sopenharmony_ci exit 1 12262306a36Sopenharmony_ci fi 12362306a36Sopenharmony_ci fi 12462306a36Sopenharmony_ci if [ ! -L $CLASS ]; then break; fi 12562306a36Sopenharmony_ci # Go down one more level of symbolic links 12662306a36Sopenharmony_ci let LINKLEVEL+=1 12762306a36Sopenharmony_ci if [ $LINKLEVEL -gt 5 ]; then 12862306a36Sopenharmony_ci exec 1>&2 12962306a36Sopenharmony_ci echo $0: 13062306a36Sopenharmony_ci echo " Too many symbolic links encountered" 13162306a36Sopenharmony_ci exit 1 13262306a36Sopenharmony_ci fi 13362306a36Sopenharmony_ci CLASS=`ls --color=no -l $CLASS | sed -e 's/^.* \([^ ]*\)$/\1/'` 13462306a36Sopenharmony_ci done 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci if [ -z "$CLASSBASE" ]; then 13762306a36Sopenharmony_ci if [ -z "$FQCLASSP" ]; then 13862306a36Sopenharmony_ci GOODNAME=$FQCLASSN.class 13962306a36Sopenharmony_ci else 14062306a36Sopenharmony_ci GOODNAME=$FQCLASSP/$FQCLASSN.class 14162306a36Sopenharmony_ci fi 14262306a36Sopenharmony_ci exec 1>&2 14362306a36Sopenharmony_ci echo $0: 14462306a36Sopenharmony_ci echo " $FQCLASS should be in a file called $GOODNAME" 14562306a36Sopenharmony_ci exit 1 14662306a36Sopenharmony_ci fi 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci if ! echo $CLASSPATH | grep -q "^\(.*:\)*$CLASSBASE\(:.*\)*"; then 14962306a36Sopenharmony_ci # class is not in CLASSPATH, so prepend dir of class to CLASSPATH 15062306a36Sopenharmony_ci if [ -z "${CLASSPATH}" ] ; then 15162306a36Sopenharmony_ci export CLASSPATH=$CLASSBASE 15262306a36Sopenharmony_ci else 15362306a36Sopenharmony_ci export CLASSPATH=$CLASSBASE:$CLASSPATH 15462306a36Sopenharmony_ci fi 15562306a36Sopenharmony_ci fi 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci shift 15862306a36Sopenharmony_ci /usr/bin/java $FQCLASS "$@" 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cijavaclassname.c: 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci.. code-block:: c 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci /* javaclassname.c 16562306a36Sopenharmony_ci * 16662306a36Sopenharmony_ci * Extracts the class name from a Java class file; intended for use in a Java 16762306a36Sopenharmony_ci * wrapper of the type supported by the binfmt_misc option in the Linux kernel. 16862306a36Sopenharmony_ci * 16962306a36Sopenharmony_ci * Copyright (C) 1999 Colin J. Watson <cjw44@cam.ac.uk>. 17062306a36Sopenharmony_ci * 17162306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 17262306a36Sopenharmony_ci * it under the terms of the GNU General Public License as published by 17362306a36Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 17462306a36Sopenharmony_ci * (at your option) any later version. 17562306a36Sopenharmony_ci * 17662306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, 17762306a36Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 17862306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17962306a36Sopenharmony_ci * GNU General Public License for more details. 18062306a36Sopenharmony_ci * 18162306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 18262306a36Sopenharmony_ci * along with this program; if not, write to the Free Software 18362306a36Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci #include <stdlib.h> 18762306a36Sopenharmony_ci #include <stdio.h> 18862306a36Sopenharmony_ci #include <stdarg.h> 18962306a36Sopenharmony_ci #include <sys/types.h> 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci /* From Sun's Java VM Specification, as tag entries in the constant pool. */ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci #define CP_UTF8 1 19462306a36Sopenharmony_ci #define CP_INTEGER 3 19562306a36Sopenharmony_ci #define CP_FLOAT 4 19662306a36Sopenharmony_ci #define CP_LONG 5 19762306a36Sopenharmony_ci #define CP_DOUBLE 6 19862306a36Sopenharmony_ci #define CP_CLASS 7 19962306a36Sopenharmony_ci #define CP_STRING 8 20062306a36Sopenharmony_ci #define CP_FIELDREF 9 20162306a36Sopenharmony_ci #define CP_METHODREF 10 20262306a36Sopenharmony_ci #define CP_INTERFACEMETHODREF 11 20362306a36Sopenharmony_ci #define CP_NAMEANDTYPE 12 20462306a36Sopenharmony_ci #define CP_METHODHANDLE 15 20562306a36Sopenharmony_ci #define CP_METHODTYPE 16 20662306a36Sopenharmony_ci #define CP_INVOKEDYNAMIC 18 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci /* Define some commonly used error messages */ 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci #define seek_error() error("%s: Cannot seek\n", program) 21162306a36Sopenharmony_ci #define corrupt_error() error("%s: Class file corrupt\n", program) 21262306a36Sopenharmony_ci #define eof_error() error("%s: Unexpected end of file\n", program) 21362306a36Sopenharmony_ci #define utf8_error() error("%s: Only ASCII 1-255 supported\n", program); 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci char *program; 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci long *pool; 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci u_int8_t read_8(FILE *classfile); 22062306a36Sopenharmony_ci u_int16_t read_16(FILE *classfile); 22162306a36Sopenharmony_ci void skip_constant(FILE *classfile, u_int16_t *cur); 22262306a36Sopenharmony_ci void error(const char *format, ...); 22362306a36Sopenharmony_ci int main(int argc, char **argv); 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci /* Reads in an unsigned 8-bit integer. */ 22662306a36Sopenharmony_ci u_int8_t read_8(FILE *classfile) 22762306a36Sopenharmony_ci { 22862306a36Sopenharmony_ci int b = fgetc(classfile); 22962306a36Sopenharmony_ci if(b == EOF) 23062306a36Sopenharmony_ci eof_error(); 23162306a36Sopenharmony_ci return (u_int8_t)b; 23262306a36Sopenharmony_ci } 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci /* Reads in an unsigned 16-bit integer. */ 23562306a36Sopenharmony_ci u_int16_t read_16(FILE *classfile) 23662306a36Sopenharmony_ci { 23762306a36Sopenharmony_ci int b1, b2; 23862306a36Sopenharmony_ci b1 = fgetc(classfile); 23962306a36Sopenharmony_ci if(b1 == EOF) 24062306a36Sopenharmony_ci eof_error(); 24162306a36Sopenharmony_ci b2 = fgetc(classfile); 24262306a36Sopenharmony_ci if(b2 == EOF) 24362306a36Sopenharmony_ci eof_error(); 24462306a36Sopenharmony_ci return (u_int16_t)((b1 << 8) | b2); 24562306a36Sopenharmony_ci } 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci /* Reads in a value from the constant pool. */ 24862306a36Sopenharmony_ci void skip_constant(FILE *classfile, u_int16_t *cur) 24962306a36Sopenharmony_ci { 25062306a36Sopenharmony_ci u_int16_t len; 25162306a36Sopenharmony_ci int seekerr = 1; 25262306a36Sopenharmony_ci pool[*cur] = ftell(classfile); 25362306a36Sopenharmony_ci switch(read_8(classfile)) 25462306a36Sopenharmony_ci { 25562306a36Sopenharmony_ci case CP_UTF8: 25662306a36Sopenharmony_ci len = read_16(classfile); 25762306a36Sopenharmony_ci seekerr = fseek(classfile, len, SEEK_CUR); 25862306a36Sopenharmony_ci break; 25962306a36Sopenharmony_ci case CP_CLASS: 26062306a36Sopenharmony_ci case CP_STRING: 26162306a36Sopenharmony_ci case CP_METHODTYPE: 26262306a36Sopenharmony_ci seekerr = fseek(classfile, 2, SEEK_CUR); 26362306a36Sopenharmony_ci break; 26462306a36Sopenharmony_ci case CP_METHODHANDLE: 26562306a36Sopenharmony_ci seekerr = fseek(classfile, 3, SEEK_CUR); 26662306a36Sopenharmony_ci break; 26762306a36Sopenharmony_ci case CP_INTEGER: 26862306a36Sopenharmony_ci case CP_FLOAT: 26962306a36Sopenharmony_ci case CP_FIELDREF: 27062306a36Sopenharmony_ci case CP_METHODREF: 27162306a36Sopenharmony_ci case CP_INTERFACEMETHODREF: 27262306a36Sopenharmony_ci case CP_NAMEANDTYPE: 27362306a36Sopenharmony_ci case CP_INVOKEDYNAMIC: 27462306a36Sopenharmony_ci seekerr = fseek(classfile, 4, SEEK_CUR); 27562306a36Sopenharmony_ci break; 27662306a36Sopenharmony_ci case CP_LONG: 27762306a36Sopenharmony_ci case CP_DOUBLE: 27862306a36Sopenharmony_ci seekerr = fseek(classfile, 8, SEEK_CUR); 27962306a36Sopenharmony_ci ++(*cur); 28062306a36Sopenharmony_ci break; 28162306a36Sopenharmony_ci default: 28262306a36Sopenharmony_ci corrupt_error(); 28362306a36Sopenharmony_ci } 28462306a36Sopenharmony_ci if(seekerr) 28562306a36Sopenharmony_ci seek_error(); 28662306a36Sopenharmony_ci } 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci void error(const char *format, ...) 28962306a36Sopenharmony_ci { 29062306a36Sopenharmony_ci va_list ap; 29162306a36Sopenharmony_ci va_start(ap, format); 29262306a36Sopenharmony_ci vfprintf(stderr, format, ap); 29362306a36Sopenharmony_ci va_end(ap); 29462306a36Sopenharmony_ci exit(1); 29562306a36Sopenharmony_ci } 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_ci int main(int argc, char **argv) 29862306a36Sopenharmony_ci { 29962306a36Sopenharmony_ci FILE *classfile; 30062306a36Sopenharmony_ci u_int16_t cp_count, i, this_class, classinfo_ptr; 30162306a36Sopenharmony_ci u_int8_t length; 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ci program = argv[0]; 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci if(!argv[1]) 30662306a36Sopenharmony_ci error("%s: Missing input file\n", program); 30762306a36Sopenharmony_ci classfile = fopen(argv[1], "rb"); 30862306a36Sopenharmony_ci if(!classfile) 30962306a36Sopenharmony_ci error("%s: Error opening %s\n", program, argv[1]); 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci if(fseek(classfile, 8, SEEK_SET)) /* skip magic and version numbers */ 31262306a36Sopenharmony_ci seek_error(); 31362306a36Sopenharmony_ci cp_count = read_16(classfile); 31462306a36Sopenharmony_ci pool = calloc(cp_count, sizeof(long)); 31562306a36Sopenharmony_ci if(!pool) 31662306a36Sopenharmony_ci error("%s: Out of memory for constant pool\n", program); 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci for(i = 1; i < cp_count; ++i) 31962306a36Sopenharmony_ci skip_constant(classfile, &i); 32062306a36Sopenharmony_ci if(fseek(classfile, 2, SEEK_CUR)) /* skip access flags */ 32162306a36Sopenharmony_ci seek_error(); 32262306a36Sopenharmony_ci 32362306a36Sopenharmony_ci this_class = read_16(classfile); 32462306a36Sopenharmony_ci if(this_class < 1 || this_class >= cp_count) 32562306a36Sopenharmony_ci corrupt_error(); 32662306a36Sopenharmony_ci if(!pool[this_class] || pool[this_class] == -1) 32762306a36Sopenharmony_ci corrupt_error(); 32862306a36Sopenharmony_ci if(fseek(classfile, pool[this_class] + 1, SEEK_SET)) 32962306a36Sopenharmony_ci seek_error(); 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci classinfo_ptr = read_16(classfile); 33262306a36Sopenharmony_ci if(classinfo_ptr < 1 || classinfo_ptr >= cp_count) 33362306a36Sopenharmony_ci corrupt_error(); 33462306a36Sopenharmony_ci if(!pool[classinfo_ptr] || pool[classinfo_ptr] == -1) 33562306a36Sopenharmony_ci corrupt_error(); 33662306a36Sopenharmony_ci if(fseek(classfile, pool[classinfo_ptr] + 1, SEEK_SET)) 33762306a36Sopenharmony_ci seek_error(); 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci length = read_16(classfile); 34062306a36Sopenharmony_ci for(i = 0; i < length; ++i) 34162306a36Sopenharmony_ci { 34262306a36Sopenharmony_ci u_int8_t x = read_8(classfile); 34362306a36Sopenharmony_ci if((x & 0x80) || !x) 34462306a36Sopenharmony_ci { 34562306a36Sopenharmony_ci if((x & 0xE0) == 0xC0) 34662306a36Sopenharmony_ci { 34762306a36Sopenharmony_ci u_int8_t y = read_8(classfile); 34862306a36Sopenharmony_ci if((y & 0xC0) == 0x80) 34962306a36Sopenharmony_ci { 35062306a36Sopenharmony_ci int c = ((x & 0x1f) << 6) + (y & 0x3f); 35162306a36Sopenharmony_ci if(c) putchar(c); 35262306a36Sopenharmony_ci else utf8_error(); 35362306a36Sopenharmony_ci } 35462306a36Sopenharmony_ci else utf8_error(); 35562306a36Sopenharmony_ci } 35662306a36Sopenharmony_ci else utf8_error(); 35762306a36Sopenharmony_ci } 35862306a36Sopenharmony_ci else if(x == '/') putchar('.'); 35962306a36Sopenharmony_ci else putchar(x); 36062306a36Sopenharmony_ci } 36162306a36Sopenharmony_ci putchar('\n'); 36262306a36Sopenharmony_ci free(pool); 36362306a36Sopenharmony_ci fclose(classfile); 36462306a36Sopenharmony_ci return 0; 36562306a36Sopenharmony_ci } 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_cijarwrapper:: 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci #!/bin/bash 37062306a36Sopenharmony_ci # /usr/local/java/bin/jarwrapper - the wrapper for binfmt_misc/jar 37162306a36Sopenharmony_ci 37262306a36Sopenharmony_ci java -jar $1 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_ciNow simply ``chmod +x`` the ``.class``, ``.jar`` and/or ``.html`` files you 37662306a36Sopenharmony_ciwant to execute. 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ciTo add a Java program to your path best put a symbolic link to the main 37962306a36Sopenharmony_ci.class file into /usr/bin (or another place you like) omitting the .class 38062306a36Sopenharmony_ciextension. The directory containing the original .class file will be 38162306a36Sopenharmony_ciadded to your CLASSPATH during execution. 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ciTo test your new setup, enter in the following simple Java app, and name 38562306a36Sopenharmony_ciit "HelloWorld.java": 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci.. code-block:: java 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci class HelloWorld { 39062306a36Sopenharmony_ci public static void main(String args[]) { 39162306a36Sopenharmony_ci System.out.println("Hello World!"); 39262306a36Sopenharmony_ci } 39362306a36Sopenharmony_ci } 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ciNow compile the application with:: 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ci javac HelloWorld.java 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ciSet the executable permissions of the binary file, with:: 40062306a36Sopenharmony_ci 40162306a36Sopenharmony_ci chmod 755 HelloWorld.class 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ciAnd then execute it:: 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci ./HelloWorld.class 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ciTo execute Java Jar files, simple chmod the ``*.jar`` files to include 40962306a36Sopenharmony_cithe execution bit, then just do:: 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci ./Application.jar 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ciTo execute Java Applets, simple chmod the ``*.html`` files to include 41562306a36Sopenharmony_cithe execution bit, then just do:: 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci ./Applet.html 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_cioriginally by Brian A. Lantz, brian@lantz.com 42162306a36Sopenharmony_ciheavily edited for binfmt_misc by Richard Günther 42262306a36Sopenharmony_cinew scripts by Colin J. Watson <cjw44@cam.ac.uk> 42362306a36Sopenharmony_ciadded executable Jar file support by Kurt Huwig <kurt@iku-netz.de> 424