launch java(swing) applications from c/c++ on mac os x

Discussion in 'Java' started by pratik.ganguly@gmail.com, Mar 22, 2005.

  1. Guest

    I want to launch a java application, which has lots of swing stuff in
    it, as also underlying algorithms running. I work on Mac OS X 10.3.8,
    and have Java 1.4.2_05(latest). I tried to launch AWT components like
    Frame,Panel, etc and it worked fine, but swing won't. I discovered that
    the code by default loads Java 1.3.1, and JNI 1.2, and hence no swing
    is supported. Can someone help me out? Thanks in advance. Here is a
    snippet of the native(c) code:

    JNIEnv* create_vm() {
    JavaVM* jvm;
    JNIEnv* env;
    JavaVMInitArgs args;
    jint jintVMStartupReturnValue;
    //JavaVMOption options[1];
    JavaVMOption options[15];

    args.version = JNI_VERSION_1_4;
    args.nOptions = 15;
    options[0].optionString =
    "-Djava.class.path=/Users/avisere12/Desktop";
    options[1].optionString =
    "-Dsun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Libraries";
    options[2].optionString = "-Xms16M";
    options[3].optionString = "-Xmx512M";
    options[4].optionString = "-Duser.dir=/Users/avisere12/Desktop";
    options[5].optionString =
    "-Djava.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home";
    options[6].optionString =
    "-Djava.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext";

    options[7].optionString =
    "-Dsun.boot.class.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/charsets.jar";
    options[8].optionString = "-Djava.runtime.version=1.4.2_05-141.4";
    options[9].optionString =
    "-Djava.awt.graphicsenv=apple.awt.CGraphicsEnvironment";
    options[10].optionString =
    "-Djava.endorsed.dirs=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/endorsed";
    options[11].optionString = "-Djava.vm.info=mixed mode";
    options[12].optionString = "-Djava.version=1.4.2_05";
    options[13].optionString = "-Djava.vm.version=1.4.2-38";
    options[14].optionString = "-Dawt.nativeDoubleBuffering=true";
    args.options = options;
    args.ignoreUnrecognized = JNI_TRUE;
    jintVMStartupReturnValue = JNI_CreateJavaVM(&jvm, &env, &args);

    return env;
    }

    void invoke_class(JNIEnv* env) {
    jclass helloWorldClass;
    jmethodID mainMethod;
    jobjectArray applicationArgs;
    jstring applicationArg0;

    helloWorldClass = env->FindClass("com/mypack/pack/MyJava");

    if(helloWorldClass == 0){
    printf("Class not found\n");
    fflush(stdout);
    }
    else{
    printf("Class found and about to be loaded\n");
    fflush(stdout);
    }

    mainMethod = env->GetStaticMethodID(helloWorldClass, "main",
    "([Ljava/lang/String;)V");

    applicationArgs = env->NewObjectArray(1,
    env->FindClass("java/lang/String"), NULL);
    applicationArg0 = env->NewStringUTF("yahoooooooo");

    env->SetObjectArrayElement(applicationArgs, 0, applicationArg0);

    env->CallStaticVoidMethod(helloWorldClass, mainMethod,
    applicationArgs);
    }


    int main(int argc, char **argv) {
    JNIEnv* env = create_vm();
    invoke_class( env );
    }
    Here is the error which I get, more so when i try to run JNI 1.4:

    2005-03-22 11:24:56.399 myapp[628] Apple AWT Java VM was loaded on
    first thread -- can't start AWT.
    Class not found
    Bus error



    I tried providing various optons as vm arguments, but got the same
    errors as above.
    , Mar 22, 2005
    #1
    1. Advertising

  2. In article <>,
    wrote:

    > I want to launch a java application, which has lots of swing stuff in
    > it, as also underlying algorithms running. I work on Mac OS X 10.3.8,
    > and have Java 1.4.2_05(latest). I tried to launch AWT components like
    > Frame,Panel, etc and it worked fine, but swing won't. I discovered that
    > the code by default loads Java 1.3.1, and JNI 1.2, and hence no swing
    > is supported. Can someone help me out? Thanks in advance. Here is a
    > snippet of the native(c) code:
    >
    > JNIEnv* create_vm() {
    > JavaVM* jvm;
    > JNIEnv* env;
    > JavaVMInitArgs args;
    > jint jintVMStartupReturnValue;
    > //JavaVMOption options[1];
    > JavaVMOption options[15];
    >
    > args.version = JNI_VERSION_1_4;
    > args.nOptions = 15;
    > options[0].optionString =
    > "-Djava.class.path=/Users/avisere12/Desktop";
    > options[1].optionString =
    > "-Dsun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/Versions/
    > 1.4.2/Libraries";
    > options[2].optionString = "-Xms16M";
    > options[3].optionString = "-Xmx512M";
    > options[4].optionString = "-Duser.dir=/Users/avisere12/Desktop";
    > options[5].optionString =
    > "-Djava.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home";
    > options[6].optionString =
    > "-Djava.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/Sys
    > tem/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext";
    >
    > options[7].optionString =
    > "-Dsun.boot.class.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.
    > 4.2/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1
    > .4.2/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2
    > /Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Cl
    > asses/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.
    > 2/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/
    > Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Cla
    > sses/charsets.jar";
    > options[8].optionString = "-Djava.runtime.version=1.4.2_05-141.4";
    > options[9].optionString =
    > "-Djava.awt.graphicsenv=apple.awt.CGraphicsEnvironment";
    > options[10].optionString =
    > "-Djava.endorsed.dirs=/System/Library/Frameworks/JavaVM.framework/Versions/1.4
    > .2/Home/lib/endorsed";
    > options[11].optionString = "-Djava.vm.info=mixed mode";
    > options[12].optionString = "-Djava.version=1.4.2_05";
    > options[13].optionString = "-Djava.vm.version=1.4.2-38";
    > options[14].optionString = "-Dawt.nativeDoubleBuffering=true";
    > args.options = options;
    > args.ignoreUnrecognized = JNI_TRUE;
    > jintVMStartupReturnValue = JNI_CreateJavaVM(&jvm, &env, &args);
    >
    > return env;
    > }
    >
    > void invoke_class(JNIEnv* env) {
    > jclass helloWorldClass;
    > jmethodID mainMethod;
    > jobjectArray applicationArgs;
    > jstring applicationArg0;
    >
    > helloWorldClass = env->FindClass("com/mypack/pack/MyJava");
    >
    > if(helloWorldClass == 0){
    > printf("Class not found\n");
    > fflush(stdout);
    > }
    > else{
    > printf("Class found and about to be loaded\n");
    > fflush(stdout);
    > }
    >
    > mainMethod = env->GetStaticMethodID(helloWorldClass, "main",
    > "([Ljava/lang/String;)V");
    >
    > applicationArgs = env->NewObjectArray(1,
    > env->FindClass("java/lang/String"), NULL);
    > applicationArg0 = env->NewStringUTF("yahoooooooo");
    >
    > env->SetObjectArrayElement(applicationArgs, 0, applicationArg0);
    >
    > env->CallStaticVoidMethod(helloWorldClass, mainMethod,
    > applicationArgs);
    > }
    >
    >
    > int main(int argc, char **argv) {
    > JNIEnv* env = create_vm();
    > invoke_class( env );
    > }
    > Here is the error which I get, more so when i try to run JNI 1.4:
    >
    > 2005-03-22 11:24:56.399 myapp[628] Apple AWT Java VM was loaded on
    > first thread -- can't start AWT.
    > Class not found
    > Bus error
    >
    >
    >
    > I tried providing various optons as vm arguments, but got the same
    > errors as above.


    I haven't used JNI in OS X and thus can't speak to your code or the
    specific problem solution. But wherever you heard that there's no Swing
    in Apple's Java 1.3.1 was dead wrong. Apple's Java releases, other than
    any bugs or documented limitations/differences, are essentially
    compatible with Sun's releases of the same number. Apple's 1.3.1 does
    in fact support Swing.

    = Steve =
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, Mar 22, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JDS
    Replies:
    4
    Views:
    8,213
    ForestHonerkamp
    Nov 11, 2008
  2. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    488
    Pete Barrett
    Apr 16, 2005
  3. Replies:
    8
    Views:
    1,676
    Andrew Thompson
    Nov 4, 2008
  4. JDS
    Replies:
    3
    Views:
    170
    gnari
    May 24, 2004
  5. Ann
    Replies:
    0
    Views:
    137
Loading...

Share This Page