Cpp swig JNI_CreateJavaVM

Hi,
I wrapped a cpp Project with SWIG to Java. Now I want to expand my cpp Project with new Java Class.
Here some Questions:
is it possible to create a JVM from a Java Object, that calls a cpp Object (wrapped code) at least this cpp Object should create a JVM - to add new Java classes to my cpp Project?
Silly questions, perhaps someone can help me!!
The first problem i want to solve, can I create 2 JVM (JNI_CreateJavaVM)?
Cheers
Edited by: cold_coffee on Dec 17, 2007 9:06 AM

is it possible to create a JVM from a Java Object,Definitely not. Chicken and egg.
The first problem i want to solve, can I create 2 JVM (JNI_CreateJavaVM)?In the same process? Not with the Sun VM you can't.
- to add new Java classes to my cpp Project?You can of course use reflection in java to access previously unknown classes. Thus you can certainly code the same in JNI. Note that myself I wouldn't do that because it would take 10 times as much code as it would take in java.

Similar Messages

  • JNI Invocation: open file in Java, write file in CPP

    Hello,
    Warning: I am a dunce, bad CPP code ahead!
    Using JNI invocation, I am trying to read a binary file in Java and write it in CPP.
    Everything compiles and runs without error, but the input and output jpg files are of course different.
    TIA to any help,
    kirst
    (begin ByteMe.java)
    import java.io.*;
    public class ByteMe
        // Returns the contents of the file in a byte array.
        public byte[] getBytesFromFile(String strInfo) throws IOException
            System.out.println("Testing:" + strInfo);
            File file = new File("1.jpg");
            InputStream is = new FileInputStream(file);
            // Get the size of the file
            long length = file.length();
            // Create the byte array to hold the data
            byte[] bytes = new byte[(int)length];
            // Read in the bytes
            int offset = 0;
            int numRead = 0;
            while (offset < bytes.length
                   && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
                offset += numRead;
            // Ensure all the bytes have been read in
            if (offset < bytes.length)
                throw new IOException("Could not completely read file "+file.getName());
            // Close the input stream and return bytes
            is.close();
            return bytes;
        public ByteMe()
              //System.out.println("in constructor");
    }(end ByteMe.java)
    (begin ByteMe.cpp)
    #include <stdlib.h>
    #include <string.h>
    #include <jni.h>
    #include <windows.h>
    // for file operations:
    #include <fstream>
    int main( int argc, char *argv[] )
         JNIEnv *env;
         JavaVM *jvm;
         JavaVMInitArgs vm_args;
         JavaVMOption options[5];
         jint res;
         jclass cls;
         jmethodID mid;
         jstring jstr;
         jobject obj_print;
         options[0].optionString = "-Xms4M";
         options[1].optionString = "-Xmx64M";
         options[2].optionString = "-Xss512K";
         options[3].optionString = "-Xoss400K";
         options[4].optionString = "-Djava.class.path=.";
         vm_args.version = JNI_VERSION_1_4;
         vm_args.options = options;
         vm_args.nOptions = 5;
         vm_args.ignoreUnrecognized = JNI_FALSE;
         // Create the Java VM
         res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         if (res < 0)
              printf("Can't create Java VM");
              goto destroy;
         cls = env->FindClass("ByteMe");
         if (cls == 0)
              printf("Can't find ByteMe class");
              goto destroy;
         jmethodID id_construct = env->GetMethodID(cls,"<init>","()V");
         jstr = env->NewStringUTF(" from C++\n");
         obj_print = env->NewObject(cls,id_construct);
         // signature obtained using javap -s -p ByteMe
         mid = env->GetMethodID(cls, "getBytesFromFile", "(Ljava/lang/String;)[B");
         if (mid == 0)
              printf("Can't find ByteMe.getBytesFromFile\n");
              goto destroy;
         else
              jbyteArray jbuf = (jbyteArray) env->CallObjectMethod(obj_print,mid,jstr);
              jlong size = jsize(jbuf);
              printf("size is: %d\n", size); // size shown in output is
              std::ofstream out("data.jpg", std::ios::binary);
              out.write ((const char *)jbuf, 100000);     
         destroy:
             if (env->ExceptionOccurred())
                env->ExceptionDescribe();
        jvm->DestroyJavaVM();
    }(end ByteMe.cpp)

    Hello,
    Me again. Well, not such a dunce after all. Here is code that works correctly, and compiles with no errors and no warnings.
    Will much appreciate help with clean-up code.
    TIA,
    kirst
    (begin ByteMe.java)
    import java.io.*;
    public class ByteMe
        public long getFilezize(String strInfo) throws IOException
              // demonstrates String parameter passed from CPP to Java:
              System.out.println("(getFilesize) Hello world" + strInfo);
              File file = new File("1.bmp");
              InputStream is = new FileInputStream(file);
              // Get the size of the file
              long length = file.length();
              is.close();
              return length;
        // Returns the contents of the file in a byte array.
        public byte[] getBytesFromFile(String strInfo) throws IOException
            System.out.println("(getBytesFromFile) Hello world" + strInfo);
            File file = new File("1.bmp");
            InputStream is = new FileInputStream(file);
            // Get the size of the file
            long length = file.length();
            System.out.println("length is: " + String.valueOf(length));
            // Create the byte array to hold the data
            byte[] bytes = new byte[(int)length];
            // Read in the bytes
            int offset = 0;
            int numRead = 0;
            while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
                offset += numRead;
            // Ensure all the bytes have been read in
            if (offset < bytes.length)
                throw new IOException("Could not completely read file "+ file.getName());
            // Close the input stream and return bytes
            is.close();
            return bytes;
        public ByteMe()
              //System.out.println("in constructor");
    }(end ByteMe.java)
    (begin ByteMe.cpp)
              Signature obtained with command:
                   "C:\Program Files\Java\jdk1.5.0_15\bin\javap.exe" -s -p ByteMe
                   Compiled from "ByteMe.java"
                   public class ByteMe extends java.lang.Object{
                   public long getFilezize(java.lang.String)   throws java.io.IOException;
                     Signature: (Ljava/lang/String;)J
                   public byte[] getBytesFromFile(java.lang.String)   throws java.io.IOException;
                     Signature: (Ljava/lang/String;)[B
                   public ByteMe();
                     Signature: ()V
         Compiled VC++ 2005 Express, run on Vista
    #include <stdlib.h>
    #include <string.h>
    #include <jni.h>
    // file operations
    #include <fstream>
    int main( int argc, char *argv[] )
         JNIEnv *env;
         JavaVM *jvm;
         JavaVMInitArgs vm_args;
         JavaVMOption options[5];
         jint res;
         jclass cls;
         jmethodID mid;
         jmethodID sizeid;
         jstring jstr;
         jobject obj_print;
         jlong filesize;
         options[0].optionString = "-Xms4M";
         options[1].optionString = "-Xmx64M";
         options[2].optionString = "-Xss512K";
         options[3].optionString = "-Xoss400K";
         options[4].optionString = "-Djava.class.path=.";
         vm_args.version = JNI_VERSION_1_4;
         vm_args.options = options;
         vm_args.nOptions = 5;
         vm_args.ignoreUnrecognized = JNI_FALSE;
         // Create the Java VM
         res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         if (res < 0)
              printf("Can't create Java VM");
              goto destroy;
         cls = env->FindClass("ByteMe");
         if (cls == 0)
              printf("Can't find ByteMe class");
              goto destroy;
         jmethodID id_construct = env->GetMethodID(cls,"<init>","()V");
         printf("%s\n",id_construct);
         jstr = env->NewStringUTF(" from C++!\n");
         if (jstr == 0)
              // Normally not useful
              printf("Out of memory (could not instantiate new string jstr)\n");
              goto destroy;
         obj_print = env->NewObject(cls,id_construct);
         //BEGIN BLOCK to get file size
         sizeid = env->GetMethodID(cls, "getFilezize", "(Ljava/lang/String;)J");
         if (sizeid == 0)
              printf("Can't find ByteMe.getFilezize\n");
              goto destroy;
         else
              printf("got here\n");
              filesize =(jlong) env->CallObjectMethod(obj_print,sizeid,jstr);
              printf("got filesize\n");
         // END BLOCK to get file size
         // BEGIN BLOCK to write file
         mid = env->GetMethodID(cls, "getBytesFromFile", "(Ljava/lang/String;)[B");
         if (mid == 0)
              printf("Can't find ByteMe.getBytesFromFile\n");
              goto destroy;
         else
              jbyteArray ret =(jbyteArray) env->CallObjectMethod(obj_print,mid,jstr);
              // Access the bytes:
              jbyte *retdata = env->GetByteArrayElements(ret, NULL);
              // write the file
              std::ofstream out("data.bmp", std::ios::binary);
              //out.write ((const char *)retdata, 921654);
              out.write ((const char *)retdata, (long)filesize);
         // END BLOCK to write file
         destroy:
             if (env->ExceptionOccurred())
                env->ExceptionDescribe();
        jvm->DestroyJavaVM();
    }(end ByteMe.cpp)

  • Why can't I build up a VM when calling JNI_CreateJavaVM?

    Hello,everyone,I got a new question,I want to call java in linux redhat 7.3,but it is strange that I failed, though my code seems quite right,please :
    #include "jni.h"
    #include "dlfcn.h"
    #include "iostream.h"
    #include "string.h"
    #define MAX_PATH 266
    typedef jint (* JNI_CREATEJAVAVM)(JavaVM **pvm, void ** penv, void *args);
    JavaVM *jvm;
    main()
         char szJvm[MAX_PATH]="/usr/java/j2re1.4.0_01/lib/i386/client/libjvm.so";
    //I will load libjvm.so with dlopen later
    //to receive JreDir
         jclass cls;
    jmethodID mid;
         int result;
         JavaVMInitArgs vm_args;
         JavaVMOption options[2];
         jint ret = -1;
         void *hLib;
         char *error=0;
         JNI_CREATEJAVAVM pfCreateJavaVM = 0;
         JNIEnv *env;
         hLib = dlopen(szJvm,RTLD_LAZY);
         if(hLib == 0)
              cout<<"Can not load library libjvm.so of Jre!"<<endl;
              return false;
         else
         cout<<"libjvm.so has been loaded in"<<endl;
         options[0].optionString = "-Djava.compiler=NONE";
         options[1].optionString = "-Djava.class.path=.";
         vm_args.version = JNI_VERSION_1_4;
         vm_args.options = options;
         vm_args.nOptions = 2; //element number of options[4]
         vm_args.ignoreUnrecognized = true;
         /*Create Java VM*/
         pfCreateJavaVM=(JNI_CREATEJAVAVM)dlsym(hLib, "JNI_CreateJavaVM");
         error=dlerror();
         if(error) //error
              //Can't Get JNI_CreatJavaVM address
              cout<<"Can not find JNI_CreatJavaVM function in libjvm.so"<<endl;
              return false;
         else
              //jvm receive the VM being created
              //env is the environment which contains all methods of java class
              ret = (*pfCreateJavaVM)(&jvm,(void**)&env,&vm_args);
         if (ret < 0)
              //failed to create VM
    cout<<"Can not create Java VM"<<endl;
    return false;
         else
         cout<<"Virtual machine has been set up"<<endl;
    And I compile it like this:
    g++ Send.cpp -rdynamic -ldl
    Then when I run it: ./a.out
    it shows error message:
    libjvm.so has been loaded in
    Error occurred during initialization of VM
    Unable to load native library: libjvm.so: cannot open shared object file: No
    such file or directory
    I don't know what has happened.Help me please,thank you!

    Asimov,
    I have worked with JNI on OS/2 and all I can suggest is the following points...
    Hello,everyone,I got a new question,I want to call
    java in linux redhat 7.3,but it is strange that I
    failed, though my code seems quite right,please :
    #include "jni.h"
    #include "dlfcn.h"
    #include "iostream.h"
    #include "string.h"
    #define MAX_PATH 266Make this "#define MAX_PATH 1024". My code would not work with this path set to anything else. It may be OS/2 related, but try this anyway.
    >
    typedef jint (* JNI_CREATEJAVAVM)(JavaVM **pvm, void
    ** penv, void *args);
    JavaVM *jvm;
    main()
    char
    szJvm[MAX_PATH]="/usr/java/j2re1.4.0_01/lib/i386/clien
    /libjvm.so";
    //I will load libjvm.so with dlopen later
    //to receive JreDir
         jclass cls;
    jmethodID mid;
         int result;
         JavaVMInitArgs vm_args;
         JavaVMOption options[2];
         jint ret = -1;
         void *hLib;
         char *error=0;
         JNI_CREATEJAVAVM pfCreateJavaVM = 0;
         JNIEnv *env;
         hLib = dlopen(szJvm,RTLD_LAZY);
         if(hLib == 0)
    cout<<"Can not load library libjvm.so of
    f Jre!"<<endl;
              return false;
         else
         cout<<"libjvm.so has been loaded in"<<endl;
         options[0].optionString = "-Djava.compiler=NONE";
         options[1].optionString = "-Djava.class.path=.";
         vm_args.version = JNI_VERSION_1_4;
         vm_args.options = options;
    vm_args.nOptions = 2; //element number of
    options[4]
         vm_args.ignoreUnrecognized = true;
         /*Create Java VM*/
         You have configured some 'user' options here but you must get the 'system arguments' for the JVM also.
    Make a call to 'JNI_GetDefaultJavaVMInitArgs( &vm_args )', then pass 'vm_args' into your JNI_CREATEJAVAVM function later.
    pfCreateJavaVM=(JNI_CREATEJAVAVM)dlsym(hLib,
    , "JNI_CreateJavaVM");
         error=dlerror();
         if(error) //error
              //Can't Get JNI_CreatJavaVM address
    cout<<"Can not find JNI_CreatJavaVM function in
    n libjvm.so"<<endl;
              return false;
         else
              //jvm receive the VM being created
    //env is the environment which contains all methods
    s of java class
    ret =
    = (*pfCreateJavaVM)(&jvm,(void**)&env,&vm_args);
         if (ret < 0)
              //failed to create VM
    cout<<"Can not create Java VM"<<endl;
    return false;
         else
         cout<<"Virtual machine has been set up"<<endl;
    And I compile it like this:
    g++ Send.cpp -rdynamic -ldl
    Then when I run it: ./a.out
    it shows error message:
    libjvm.so has been loaded in
    Error occurred during initialization of VM
    Unable to load native library: libjvm.so: cannot
    t open shared object file: No
    such file or directory
    I don't know what has happened.Help me please,thank
    you!
    Try those small things and let me know what it returns.
    Bryan Galvin.
    Software Engineer.

  • JNI_CreateJavaVM method crashed

    I m trying to Invoke Java from Cpp code for a certain application.
    I m using JDK 1.5
    Please Help me in sorting out the problem.
    Thank u in advance
    I m posting the sample code which i tried
    #include "jni.h"
    #include <dlfcn.h>
    #include <link.h>
    #include <iostream>
    using namespace std;
    void *g_handle_open = NULL;
    JavaVM *g_Jvm     = NULL;     
    typedef int (JNICALL JCF_CREATE_JAVA_VM)(JavaVM *, void **, JavaVMInitArgs *);
    struct JCFJAVA
    JNIEnv *env;          // JNI interface pointer
    jclass jclsClass;     // Java class object
    jmethodID jmid;          // Method ID
    jobjectArray jObjArgs; // JavaVM option
    jint jnReturnFlag;          // Return value of method of Java
    main()
    int ret_jvmInvoke =0;
    JCFJAVA *r_stobject;
    JavaVMInitArgs stVM_args;
    JavaVMOption stJVMPptions[1] =
         {   NULL,                              
    char pszJvm_path[]="/opt/jp1imm/bin/jre/lib/sparc/client/libjvm.so";
    // libjvm.so is present in the above mentioned in the path
    g_handle_open = dlopen(pszJvm_path, RTLD_LAZY);
    if (g_handle_open == NULL)
    cout << "g_handle_open NULL" << endl;
    JCF_CREATE_JAVA_VM jcfJNICreateJavaVM = (JCF_CREATE_JAVA_VM) dlsym(g_handle_open,"JNI_CreateJavaVM");
    stJVMPptions[0].optionString = "-XX:+AllowUserSignalHandlers";
    stVM_args.nOptions = 1;
    stVM_args.version = JNI_VERSION_1_4;
    stVM_args.options = stJVMPptions;
    stVM_args.ignoreUnrecognized = JNI_TRUE;
    ret_jvmInvoke = jcfJNICreateJavaVM(&g_Jvm, (void**)&(r_stobject->env), &stVM_args);
    cout << ret_jvmInvoke << endl;
    Error Message
    bash-2.05b# ./a.out
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # SIGSEGV (0xb) at pc=0x00000000, pid=18759, tid=1
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b05 mixed mode, sharing)
    # Problematic frame:
    [error occurred during error reporting, step 60, id 0xb]
    # An error report file with more information is saved as hs_err_pid18759.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    Abort (core dumped)
    Core Details
    ash-2.05b# pstack core
    core 'core' of 18752: ./a.out
    ff03cdcc lwpkill (6, 0, ff0219cc, 42844, ff064224, 6) + 8
    fefbdd58 abort (416d8, 1, fecbe7cc, a65d0, ff067218, 0) + 110
    febb93f4 __1cCosFabort6Fi_v_ (1, 4e44, fec5c, 1d6, fecb8000, 4c00) + 58
    fec322f8 __1cHVMErrorOreport_and_die6M_v_ (0, fecd5f20, 4000, febbcaf4, fec381e2, febbcaf4) + c6c
    fec326dc __1cNcrash_handler6FipnHsiginfo_pv_v_ (b, 0, ffbfd1e8, 1, ffbfd56d, ffbfd571) + 44
    ff03bee4 __sighndlr (b, 0, ffbfd1e8, fec32698, 0, 1) + c
    ff031318 call_user_handler (b, ffbffeff, 4, ffff, ff3a2000, ffbfd1e8) + 3b8
    fec0b150 __1cIUniverseIprint_on6FpnMoutputStream__v_ (0, ffbfd770, 3d68, acee8, 0, 3c00) + 44
    fec31494 __1cHVMErrorGreport6MpnMoutputStream__v_ (ffbfd770, be, ffbfe840, 1, feca2ce8, 7d0) + aac
    fec31c3c __1cHVMErrorOreport_and_die6M_v_ (ffbfd840, fecd5f20, fecd5f58, 0, 4000, ffbfe840) + 5b0
    fec326dc __1cNcrash_handler6FipnHsiginfo_pv_v_ (b, 0, ffbfd9d8, 1, 0, 0) + 44
    ff03bee4 __sighndlr (b, 0, ffbfd9d8, fec32698, 0, 1) + c
    ff031318 call_user_handler (b, ffbffeff, 4, ffff, ff3a2000, ffbfd9d8) + 3b8
    fea9acb4 __1cFframeOprint_on_error6kMpnMoutputStream_pcii_v_ (ffbfdf68, feccd77c, fecdea28, 7d0, ffbfdef0, 0) + 38
    fec30c60 __1cHVMErrorGreport6MpnMoutputStream__v_ (ffbfdf68, 0, ffbfe840, feca6ac1, feca2ce8, 7d0) + 278
    fec31c3c __1cHVMErrorOreport_and_die6M_v_ (ffbfe038, fecd5f20, fecd5f58, 4028, 5, ffbfe840) + 5b0
    fec326dc __1cNcrash_handler6FipnHsiginfo_pv_v_ (b, 0, ffbfe1d0, 1, 0, 0) + 44
    ff03bee4 __sighndlr (b, 0, ffbfe1d0, fec32698, 0, 1) + c
    ff031318 call_user_handler (b, ffbffeff, 4, ffff, ff3a2000, ffbfe1d0) + 3b8
    fea9acb4 __1cFframeOprint_on_error6kMpnMoutputStream_pcii_v_ (ffbfe798, feccd77c, fecdea28, 7d0, ffbfe6e8, 0) + 38
    fec30c60 __1cHVMErrorGreport6MpnMoutputStream__v_ (ffbfe798, 0, ffbfe840, feca6ac1, feca2ce8, 7d0) + 278
    fec31a74 __1cHVMErrorOreport_and_die6M_v_ (ffbfe840, fecd5f20, 0, 0, 5834, 0) + 3e8
    fe9ff2f0 JVM_handle_solaris_signal (b, ffbfecc0, ffbfea08, 5000, 4, 439b0) + 9e8
    ff03bee4 __sighndlr (b, ffbfecc0, ffbfea08, fe9fe8e8, 0, 1) + c
    ff031318 call_user_handler (b, ffbffeff, c, 0, ff3a2000, ffbfea08) + 3b8
    00000000 ???????? (445b8, 45698, fdc7d5a3, 45324c, 0, fdcb8000) + ffffffff00fcf0a0
    fd86e8ec JVM_RawMonitorCreate (5a24, 44976c, fe7b0224, 5800, fdcb8000, 445b8) + 64
    fe7a219c ???????? (0, 190, 0, fe7b0000, de98, 0) + f33914
    fe7a1e38 ???????? (ffbff3a8, ffbff39c, 0, 0, 0, 6224) + f335b0
    fe7a1dfc ZIP_Open (ffbff3a8, ffbff39c, 43f78, fecd36e4, 4a68, 43f70) + 14
    fe86e6cc __1cLClassLoaderXcreate_class_path_entry6FpcnEstat_ppnOClassPathEntry__v_ (21b20, fed82140, ffbff894, fecc7fd4, 178c, 5c10) + 25c
    fe86e290 __1cLClassLoaderbBsetup_bootstrap_search_path6F_v_ (e8, 449e74, fe86da70, ffbff898, fecb8000, 0) + 110
    fe86d908 __1cLClassLoaderKinitialize6F_v_ (feccb4c0, 0, ffbff984, fecc7ff8, fec60754, b) + 184
    fe867420 __1cMinit_globals6F_i_ (ffbffb10, 439b0, 43f78, 0, 0, 43f70) + 1c
    fe859d78 __1cHThreadsJcreate_vm6FpnOJavaVMInitArgs_pi_i_ (38c, ffbffbcc, 439b0, fec9b671, 7f92e3, 7f9d10) + 454
    fe8596f4 JNI_CreateJavaVM (216e4, ff3a0740, ffbffcb4, 1, 21404, 45e9ac) + ac
    00011190 main (1, ffbffd34, ffbffd3c, 21400, 0, ff3a0740) + e8
    00010c78 _start   (0, 0, 0, 0, 0, 0) + 108                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    marko999,
    I'm trying to do the same thing your doing. Here is my C code...
    #include <stdio.h>
    #include <jni.h>
    #ifdef _WIN32
    #define PATH_SEPARATOR ';'
    #else
    #define PATH_SEPARATOR ':'
    #endif
    int main()
    JavaVMOption options[1];
    JNIEnv *env;
    JavaVM *jvm;
    JavaVMInitArgs vm_args;
    long status;
    jclass cls;
    jmethodID mid;
    jint square;
    jboolean not;
    options[0].optionString = "-Djava.class.path=.";
    memset(&vm_args, 0, sizeof(vm_args));
    vm_args.version = JNI_VERSION_1_4;
    vm_args.nOptions = 1;
    vm_args.options = options;
    status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    Here is the command I'm using to compiling the code:
    gcc -I/usr/java/include/
    -I/usr/java/include/solaris
    -L/usr/java/jre/lib/sparc/client/libjvm.so
    Sample2.c -o Sample2
    When I try to compile, I keep getting this error:
    bash-2.03$ gcc -I/usr/java/include/ -I/usr/java/include/solaris -L/usr/java/jre/lib/sparc/client/libjvm.so Sample2.c -o Sample2
    Undefined first referenced
    symbol in file
    JNI_CreateJavaVM /var/tmp/ccZPapf2.o
    ld: fatal: Symbol referencing errors. No output written to Sample2
    collect2: ld returned 1 exit status
    Whats the command you used compile your c code?
    Thanks for your advise

  • Java Application using Swig Running Visual C++ 6.0

    i,
    I am using Swig with Java ,I'm trying launch a Java application using a Windows executable,
    I'm using VC++6.0, and followed the instruction in Swig Documentation chaper 20,Section 20.2.8.
    I Build my dll in Vc++ i get this error Anyone know this,please help me.
         SWIG
         Compiling resources...
         Compiling...
         StdAfx.cpp
         Compiling...
         example.c
         Generating Code...
         Compiling...
         example_wrap.cpp
    c:\program files\java\jdk1.5.0_01\include\jni.h(46) : error C2146: syntax error : missing ';' before identifier 'jsize'
    c:\program files\java\jdk1.5.0_01\include\jni.h(46) : fatal error C1004: unexpected end of file found
    Generating Code...
    Error executing cl.exe.
    example.dll - 2 error(s), 0 warning(s)
    Regards
    Devi

    check on line 46, there might be a missing ";"
    c:\program files\java\jdk1.5.0_01\include\jni.h(46) : error C2146: syntax error : missing ';' before identifier 'jsize'

  • Can't create Java VM [Code :- 3 ] with JNI_CreateJavaVM()

    hello all,
    I am trying to create an inctance of JVM from C/CPP ( iam using VC++ editor) on windows. My code to create JVM is :
    res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
    as a reasult of this call, -3 is returned to res.
    please help me to create a JVM and/or call a java class from C/CPP
    Thanks in advance,
    Soujanya.R

    I tried to run it this way :-
    #include <jni.h>
    #include <windows.h>
    #define JNI_EVERSION (-3) /* JNI version error */
    #define PATH_SEPARATOR ';'
    #define USER_CLASSPATH "." /* where Prog.class is */
    void main() {
              JNIEnv *env;
              JavaVM jvm = (JavaVM )0;
              jint res;
              jclass cls;
              jmethodID mid;
              jstring jstr;
              jobjectArray args;
              HINSTANCE hVM = NULL;
              JavaVMInitArgs vm_args;
              JavaVMOption options[4];
              printf("\noptions");
              options[1].optionString = "-Djava.class.path=C:/j2sdk1.4.1_07/jre/lib/rt.jar;E:/test/c/Debug/"; /* user classes */
              options[2].optionString = "-Djava.library.path=lib"; /* set native library path */
              options[0].optionString = "-Djava.compiler=NONE";
              //options[1].optionString = "-Djava.class.path=c:\\My Folder"; /* user classes */
              //options[2].optionString = "-Djava.library.path=C:\\j2sdk1.4.2_04\\include";
              options[3].optionString = "-verbose:jni";
              printf("\nversion info");
              vm_args.version = JNI_VERSION_1_2;
              vm_args.options = options;
              vm_args.nOptions = 4;
              vm_args.ignoreUnrecognized = TRUE;
              printf("\ncreate");
              hVM = LoadLibrary("C:/j2sdk1.4.1_07/jre/bin/client/jvm.dll");
              if (hVM == NULL)
                   printf("hVM is null ");
              res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
              if (res < 0) {
                   fprintf(stderr, "Can't create Java VM \n",res);
                   exit(1);
              cls = env->FindClass("HelloWorld");
              //cls = env.FindClass(env,"helloWorldClass");
              if (cls == 0) {
                   fprintf(stderr, "Can't find Prog class\n");
                   exit(1);
              mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
              if (mid == 0) {
                   fprintf(stderr, "Can't find Prog.main\n");
                   exit(1);
              jstr = env->NewStringUTF(" from C!");
              if (jstr == 0) {
                   fprintf(stderr, "Out of memory\n");
                   exit(1);
              args = env->NewObjectArray(1, (*env).FindClass("java/lang/String"), jstr);
              if (args == 0) {
                   fprintf(stderr, "Out of memory\n");
                   exit(1);
              env->CallStaticVoidMethod(cls, mid, args);
              jvm->DestroyJavaVM();
    I could run the program.
    You need to have the C:\j2sdk1.4.1_07\lib\jvm.lib entries in Project->Settings->Link Tab
    When you open the Settings dialog box you will see Win32Debug in the
    drop down . You need to provide the entries for that page .
    Then change the drop down to Win32 Release and make an entry similarly there too.
    You should be able to run your code.
    Vishal                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Unigraphics CPP JNI Memory Access violation.

    I have written a CPP code to get datas from Unigraphics which internally calls java through jni. I have created a dll using vc++6.0.
    when i run the dll from Unigraphics I am getting this problem.
    Prob: memory access violation.
    But i can able to create JVM using
    res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    But when i use cls = env->FindClass("Prog");
    i am getting this error from Unigraphics.
    (Note : CPP code can be invoked only from Unigraphics. b'cos Its a internal call from unigraphics through dll. This works fine when i write external cpp code to retrive datas from Unigraphics with jni code).
    If needed vl send the code.

    thanks for your reply.
    Most of the examples I have found on the net use a 3 parameter call to getStringUTFchars looking something similar to this:
    const char *str = GetStringUTFChars( env, some_jstring, 0);However when I try and add a third param in my dll file using VC++, i get a compile error saying:
    error C2660: 'JNIEnv_::GetStringUTFChars' : function does not take 3 argumentseven though clearly in the stacktrace output I previously included, in one of the lines it says that JINEnv does take 3 params:
    at JNIEnv_.GetStringUTFChars(JNIEnv_* , _jstring* str, Byte* isCopy)I am not sure why but using 2 params is the only way i can get the dll to compile correctly.
    That is why I used      const char *cName;
         const char *wName;
         cName = env->GetStringUTFChars( className,false);
         wName = env->GetStringUTFChars( windowName, false);Also, as I said at the end of my first post, somehow the program worked a few times ( 3-4 ) without giving me the errors, and thus, gave me the intended output. However, I have not been able to get it to work since then, nor do I know what I did, or what happened so that it would work in the first place.
    -Dale
    Message was edited by:
    smithdale87

  • Using JNI_CreateJavaVM

    What do I have to link into my cpp program to use the JNI_CreateJavaVM function? I can't seem to find it...

    Hi Kabilesh,
    Could you please let me know the exast soution u had for this?
    I even set the SHLIB_PATH in the environment, but still this problem persists.
    I am compiling the program and making into a shared library as
    cc -c -g -n +z -I$JAVA_HOME/include -I$JAVA_HOME/include/hp-ux -L/opt/java1.4/jre/lib/PA_RISC2.0/server -ljvm Test.c -o Test.o
    ld -b Test.o -L/opt/java1.4/jre/lib/PA_RISC2.0/server -ljvm -o Test.slMy java code is looks like this :
    void create_Jvm()
        JNIEnv * env;
        JavaVM * jvm;
        //JDK1_1InitArgs vm_args;
        /* Note : In JNI1.2 and Java2 SDK 1.4, the new structure JavaVMInitArgs has been introduced.*/
        JavaVMInitArgs vm_args;
        //JavaVMOption options[1];
        jint res;
        vm_args.nOptions = 0;
        vm_args.ignoreUnrecognized = JNI_TRUE;
        /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
        vm_args.version = JNI_VERSION_1_4;
        //vm_args.version = JNI_VERSION_1_2;
        /*In JNI1.2 and Java2 SDK 1.4 the JNI_GetDefaultJavaVMInitArgs method call is not required.*/
        //JNI_GetDefaultJavaVMInitArgs( & vm_args);
        res = JNI_CreateJavaVM( &jvm, (void**)&env, &vm_args);
        if (res < 0) {
            fprintf(stderr, "Can't create Java VM\n Error is :%ld\n ", res);
            exit(1);
        iJvmInitialized = 1;
    } hi
    Check the lib path
    May be u have not included : at the end of the lib
    path that u have added
    THis was the mistake that i did
    kabilesh

  • Error in visualizing a Data Form "WDEFGenerator.cpp"

    Hi,
    I have migrated an HFM application from version 4.01 SP2 to version 11.1.2.1
    Everything works fine appart from an error in visualizing a Data Form:
    In the previous version of HFM this error was not verified.
    If I disable the option SuppressNoDataRows I get no errors but I would like to keep this option enabled.
    Does anyone know what could be the problem?
    The error I'm getting is:
    Error Reference Number: {3783BC27-A47D-463A-9F21-5E1C2B55A775};User Name: hypadmin@Native Directory
    Num: 0x80070057;Type: 0;DTime: 6/19/2012 4:41:11 PM;Svr: BMI-2K8-HFMPA;File: WDEFGenerator.cpp;Line: 1407;Ver: 11.1.2.1.103.3505;
    Num: 0x80070057;Type: 0;DTime: 6/19/2012 4:41:12 PM;Svr: BMI-2K8-HFMPA;File: WDEFGenerator.cpp;Line: 3284;Ver: 11.1.2.1.103.3505;
    Num: 0x80070057;Type: 0;DTime: 6/19/2012 4:41:12 PM;Svr: BMI-2K8-HFMPA;File: WDEFGenerator.cpp;Line: 3166;Ver: 11.1.2.1.103.3505;
    Num: 0x80070057;Type: 0;DTime: 6/19/2012 4:41:12 PM;Svr: BMI-2K8-HFMPA;File: CHsvWebFormGeneratorACM.cpp;Line: 3687;Ver: 11.1.2.1.103.3505;
    Num: 0x80070057;Type: 0;DTime: 6/19/2012 4:41:12 PM;Svr: BMI-2K8-HFMPA;File: CHsvWebFormGeneratorACM.cpp;Line: 3389;Ver: 11.1.2.1.103.3505;
    Num: 0x80070057;Type: 0;DTime: 6/19/2012 4:41:11 PM;Svr: BMI-2K8-HFMPW;File: CHsvWebFormsACV.cpp;Line: 569;Ver: 11.1.2.1.103.3505;
    And the data form script is:
    ReportType=WebForm
    ReportLabel=1_1_12_1
    ReportDescription=Trade Receivables > 12 months
    BackgroundPOV=S#ACT.w#<Scenario View>.V#<Entity Currency>.A#[None].I#[ICP None].C1#[None].C2#[None].C3#[None].C4#[None]
    SelectablePOVList=Y{[Hierarchy]}.P{[Second Generation]}.E{GRBRA000.[Base]}
    C1=C1{FL_CURR.[Base]}
    R1=A#3_03_01.I#[ICP Entities],AddMember:I{CONS}
    R2=A#3_03_01.I{CONS}
    R3=A#3_03_02.I#[ICP Entities],AddMember:I{ASS}
    R4=A#3_03_02.I{ASS}
    R5=A#3_03_03.I#[ICP Entities],AddMember: I{PARENT}
    R6=A#3_03_03.I{PARENT}
    R7=A#3_03_04,NoSuppress
    R8=A#3_03_1.I#[ICP Top],CustomHeaderStyle:font: bold,NoSuppress
    FormRowHeight=20 px
    PrintNumRowsPerPage=10
    PrintNumDataColsPerPage=3
    SuppressNoDataRows=True
    ShowLabels=True
    SuppressColHeaderRepeats=False
    HeaderOptionAccount=ShowLabel,ShowDescription,Length:50
    HeaderOptionICP=ShowDescription
    HeaderOptionCustom1=ShowDescription
    HeaderOptionCustom2=ShowDescription
    Thanks
    Best Regards

    Hi
    Check they have the "Data Form Write Back from Excel" role in Shared Services.
    See p.133 of the security guide for more info -
    http://docs.oracle.com/cd/E17236_01/epm.1112/hss_admin_1112200.pdf
    Regards
    jpr

  • CPP Assertion Error when navigating in Obiee 11g

    Hi,
    I have a report which uses SQL filters and I am trying to navigate from this report to another page.
    And I see the following error :
    Dashboard Display Error
    Assertion failure: isXsiTypeSqlExpression(rExpr) at line 67 of C:\ADE\aime_bi\bifndn\analytics_web\main/project/webreport/exprformulautils.cpp
    Error Details
    Error Codes: ACIOA5LN
    Some forums mentioned that re-creation of saved SQL filters would help but it didn't.
    Has anyone faced similar errors ?
    Thanks for any pointers.
    - Sujana

    Sujana,
    This is a bug in 11g, apply patch 12561330.
    Rgds,
    Dpka

  • After System Update last night, the system will not boot with IOPlatformExpert.cpp:1504 error

    I have had Lion for a 2, 3 months on the iMac 27 inch purchased last October (2011). Last night I chose to update the system, and deselected iMoves update because it was 1GB, and chose only 4 updates, including iTunes, Safari (i think)... But the update says error, and ask to restart the system (it won't restart itself, so I waited 30 minutes, and then pressed the Power button for 10 seconds, to let it power down, and press Power again to power it up).
    However, after that, the system failed to boot up, showing a
    panic(cpu 0 caller .....)" "Unable to finder driver for this platform: \"ACPI\". ... xnu-1699.26.8/iokit/Kernel/IOPlatformExpert.cpp:1504
    This is not typical of the upgrade process. So I searched the Internet forIOPlatformExpert.cpp:1504 and some people said it is a hard drive error, but then I powered down and pressed Options when booting up, and was able to boot to Windows 7 (bootcamp)... and was able to boot to the "Recovery", which let me choose
    Restore from Time Machine Backup
    Reinstall Mac OS X
    Get Help Online
    Disk Utility
    what should I do now to fix it so that it can boot again?

    This error is caused by one of the updates you applied, namely the Thunderbolt Software Update 1.2.  Many people have been affected by it, including me.  I did what Linc Davis has suggested above to fix it.  The most extensive discussion about the problem, with ways to fix the problem, is here:
    https://discussions.apple.com/thread/4020399?start=0&tstart=0

  • Adobe Media Encoder (CS5) has encountered an error (WinFile.cpp-759)

    I have a 714 MB Xvid file that I want to split into smaller pieces. I have gone successfully through a similar process earlier with a larger Xvid file using the same version of Adobe Media Encoder (CS5). It appears that no matter which output video format I choose, the process crashes with the following error message shown in a new pop-up dialog:
    "Adobe Media Encoder has encountered an error. [..\..\Src\Win\WinFile.cpp-759].
    (Even the source program file line number 759 in the above error message is always the same, regardless of my chosen output file format.)
    The only option available from this point onwards is the "Continue" button. When I click Continue the program terminates with the Windows program crash message "Adobe Media Encoder CS5 has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. <Debug> / <Close program>"
    My search for other similar problem reports revealed that some user(s) has/have experienced a very similar problem in CS4, but the source line number was slightly different in CS4. Both problems are probably caused by the same error in Adobe's software. The small difference in source line numbers is probably due to some (minor) and probably unrelated changes to this C++ source module (WinFile.cpp).
    It might of course be the case that this particular input video file has some rare encoding or other embedded problem. However, the fact that I can view the video without problems using Windows Media Player does not support this theory.
    Apart from this message board I could not find any other avenue to report this bug to Adobe (without paying for support - which I am obviously not going to do as this is clearly a programming bug in the software). Hopefully some Adobe developer responsible for Media Encoder maintenance will read this forum from time to time and would subsequently inspect the source module for any obvious defects. I could supply the source video file with which this problem can be reproduced at will.
    Regards
    Jouni Juntunen

    CS4 Adobe Media Encoder & FMLE are two different softwares - you can post your query here:http://forums.adobe.com/community/ame

  • Adobe Media Encoder CS4 Error: WinFile.cpp-754

    When encoding video from one format to another (no matter what is source and what is result file format) I have an error after some time or in the begining of the process. "Adobe Media Encoder has encountered an error ..\..\Src\Win\WinFile.cpp-754"
    Version of Encoder is 4.2.0.006 (updated).
    I can't encode any files. What is the problem?

    Any update on this?
    I get WinFile.cpp-754 on CS4 and WinFile.cpp-785 on CS5 trying to encode the same AVI file.
    I'm trying to load a 59.94 fps AVI file into PremierPro CS4 and need to convert it to something else (correct?)

  • Adobe Media Encoder Error with MPEG2 Formats [../../src/Command.cpp-2519]

    I am trying to use some of my presets using MPEG2 format and it is giving me this error: [/Volumes/BuildDisk/builds/ame602_mac/main/app/frontend/prj/mac/../../src/Command.cpp-251 9]. I try the system presets that use MPEG2 and I get the same error. I notice if I try to make a new preset, I do not even have the option to choose MPEG2. I only get MPEG4 or MPEG4 (Legacy). I am using AME 7.0.2; if anyone has an idea on why I can't use MPEG2 please let me know.
    Thanks,
    Mike

    Hi mboory,
    Please mention the exact version of Media Encoder CS6 that you are using and also the version of operating system. Please check the below link as well.
    http://forums.adobe.com/message/4402558
    Regards,
    Vinay

  • Adobe Media Encoder error when encoding: winfile.cpp-759

    Mods: Please move this to the appropriate thread wasn't sure to move it to Premiere or Flash
    I receive this error when trying to encode AVI to H.264 using Adobe Media Encoder CS5 (64bit):
    When searching through the forums, several suggestions for CS4 and current releases that I have tried are:
    clearing the media cache through AME, and the folder location in %APPDATA%\Adobe\Common\
    installing K-Lite Codec pack
    changing the media cache files folder to a separate disk entirely
    updating to the latest version (at the time of post ver 5.0.1.0)
    uninstalling and re-installing AME (as an error might have occurred during updates)
    verifying that the CPU has SSE support and is enabled
    I expanded my search to google which gave similar errors (winfile.cpp-754, winfile.cpp-758, etc.) and a few responses were uninstalling any Nero products (don't have any burning programs on this computer - unless you count Windows)
    The system that I have is:
    MS Windows 7 64-bit
    Intel Core 2 Quad Q6600 @ 2.40GHz
    2x 1.0GB Dual-Channel DDR2 @ 800MHz
    512MB GeForce 9600 GHz
    2x 250GB HDD Mirrored
    External USB 500GB HDD
    Any ideas as to what the cause of this is?
    LK.

    The information about installing codecs packs is true. It usually does more damage to your codecs already present with software already installed on your computer, and the registry settings even after removing it. That is why it is in good practice to do full image back ups monthy, saving the latest 3 for when I utilize last resort methods such as codec packs.
    Adobe CS5 software has been working fine on my computer ever since its installation July. I forgot to mention that I have successfully used Premiere Pro CS5 for editing a dozen files ranging from SD small res to HD 1080i. This also includes just using AME CS5 itself for transcoding files for supported playback on different devices. I notice a greater difference in speed when using a more up to date machine that uses a GTX 285 card for GPU playback - a lot faster and smoother.
    I have a 2nd, slightly older computer, that houses an extra drive I put in there to use as a scratch disk. I occasionally add that disk to the computer that has CS5 currently installed as a scratch disk for editing video. The external USB drive is used to store the final product and my backups.
    This error has only come up 1 time out of the 49 files I have encoded that usually run 10 minutes to 1.5 hours. I had 9 AVI files in the encoding queue and it always stopped at this 1 particular file. I skipped the file and encoded the rest successfully, but I want to know why it causes an error in AME because this has never happened before. I have even used it on a more up-to-date machine spec wise, thinking that there is a 1% possibility that it doesn't like my computer. The same error was produced. The 9 files that I did encode are roughly the same video and audio format - just this one is the error.
    I gave the file to my friend who was supposed to analyze before I got home - I usually assist them in PC problems and built his better-than-mine PC.
    Any other suggestions for this error and/or a solution?
    Lk

Maybe you are looking for