[brailleblaster] Making BrailleBlaster Directly Executable

  • From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxxx>
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Fri, 6 Aug 2010 20:16:25 -0500

We will want to have BrailleBlaster as an executable program, that is, 
an .exe file or whatever the platform requires. The JNI Reference Manual 
contains an example of how to call the JVM from a C program. I have 
adopted this for our possible use. Of course it will need more tuning, 
and will need to use the preprocessor to make it specific to various 
platforms. It is attached for your consideration. Note that this is NOT 
a comkmand-line progrram. It just gets BBrailleBlaster started. 

John B.

-- 
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities

#include <jni.h>

#define PATH_SEPARATOR ';'      /* define it to be ':' on Solaris */
#define USER_CLASSPATH "."      /* where Prog.class is */

main ()
{
  JNIEnv *env;
  JavaVM *jvm;
  jint res;
  jclass cls;
  jmethodID mid;
  jstring jstr;
  jclass stringClass;
  jobjectArray args;
  JavaVMInitArgs vm_args;
  JavaVMOption options[1];
  options[0].optionString = "-Djava.class.path=" USER_CLASSPATH;
  vm_args.version = 0x00010002;
  vm_args.options = options;
  vm_args.nOptions = 1;
  vm_args.ignoreUnrecognized = JNI_TRUE;
  /* Create the Java VM */
  res = JNI_CreateJavaVM (&jvm, (void **) &env, &vm_args);
  if (res < 0)
    {
      fprintf (stderr, "Can't create Java VM\n");
      exit (1);
    }
  cls = (*env)->FindClass (env, "org.brailleblaster.editor.Main");
  if (cls == NULL)
    goto destroy;
  mid = (*env)->GetStaticMethodID (env, cls, "main",
                                   "([Ljava/lang/String;)V");
  if (mid == NULL)
    goto destroy;
  jstr = (*env)->NewStringUTF (env, " from BrailleBlaster!");
  if (jstr == NULL)
    goto destroy;
  stringClass = (*env)->FindClass (env, "java/lang/String");
  args = (*env)->NewObjectArray (env, 1, stringClass, jstr);
  if (args == NULL)
    goto destroy;
  (*env)->CallStaticVoidMethod (env, cls, mid, args);

destroy:
  if ((*env)->ExceptionOccurred (env))
    (*env)->ExceptionDescribe (env);
  (*jvm)->DestroyJavaVM (jvm);
}

Other related posts: