JNI, invocation API

Hi,
I would like to start with JNI.
I read the JNI-Tutorial and
didn't find the file: jni.h.
Where can I get it?
I would like to write an invocation API.
A VC-program should call a java-function.
Does anybody know,
where to find the demo-code (c and java)
of a 'hello world'-program?
Thanks
Ully

Thanks bschauwe,
I tested so many things,
that I installed somethings else,
but not the sdk!

Similar Messages

  • JNI, invocation-API, JNI_CreateJavaVM

    Hi,
    I want to compile 'invoke.c' from the internet and
    get a compiler-error. Does anybody know, what to do?
    Thanks Ully
    c-code:
    #include "jni.h"
    jint res;
    JavaVM *jvm;
    JNIEnv *env;
    JDK1_1InitArgs vm_args;
    res=JNI_CreateJavaVM( &jvm, &env, &vm_args );
    compiler VC++ 6.0:
    error C2664: 'JNI_CreateJavaVM':
    cannot convert parameter 2 from 'struct JNIEnv_ ** ' to 'void ** '

    Hi,
    I want to compile 'invoke.c' from the internet and
    get a compiler-error. Does anybody know, what to do?
    Thanks Ully
    c-code:
    #include "jni.h"
    jint res;
    JavaVM *jvm;
    JNIEnv *env;
    JDK1_1InitArgs vm_args;
    res=JNI_CreateJavaVM( &jvm, &env, &vm_args );
    compiler VC++ 6.0:
    error C2664: 'JNI_CreateJavaVM':
    cannot convert parameter 2 from 'struct JNIEnv_ ** '
    to 'void ** 'Alas, you have to cast &env to (void **). The correct call looks like this:
    res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
    -Aaron

  • JNI FindClass Error: Using the Invocation API  from visual C++

    I am using JNI invocation api in microsoft visual c++ to invoke java. When I use the FindClass method, I get a return value of 0. I have verified that the class "a" exists and believe have set the java class path appropriately. A valid jvm and jenv are created. The program fails at the FindClass call and returns 0.
    std::string classPath = "c:\\work\\java;C:\\j2sdk1.4.2_08;C:\\j2sdk1.4.2_08\\bin;C:\\j2sdk1.4.2_08\\lib";
         vmArgs.classpath = classpath;
         jint res = JNI_CreateJavaVM(&jvm, (void**)(&jenv), &vmArgs);
         if (res < 0)
              cout << "Error!! Cannot create jvm" << endl;
    jclass jFixEngineClass1 = jenv->FindClass("a");
         if (jFixEngineClass1 == 0)
              cout << "Error could not find a class" << endl;
         else
              cout << "a class found" << endl;
    thanks in advance,
    hcg

    Jschell,
    Thanks for your help.
    I found the error. I was using JDK1_1InitArgs for my vm_args. Since, I am using JDK 1.4, the classpath I was setting was not getting picked up. I changed the vm_args type as in the code below and it worked.
    JavaVMInitArgs vmArgs;
         JavaVMOption options[1];
         char classPathDef[1024];classPathDef[0] = '\0';
         sprintf(classPathDef, "%s", "-Djava.class.path=");
         sprintf(classpath, "%s%s", classPathDef, NYSE_FIX::userClassPath.c_str());
         options[0].optionString = classpath;
         cout << "Option string is:" << options[0].optionString << endl;
    vmArgs.version = 0x00010004;
    vmArgs.options = options;
    vmArgs.nOptions = 1;
    vmArgs.ignoreUnrecognized = JNI_TRUE;
         jint ret = JNI_GetDefaultJavaVMInitArgs(&vmArgs);

  • VC8 clients and native invocation API

    Hi,
    Could someone from Sun tell me whether JNI invocation API for the 1.5.0_07 Windows JVM supports .NET clients compiled with Visual C++ 8?
    I have an ASP.NET application that calls into the JVM through the JNI invocation API. I know that there were problems with VC7 clients calling into the 1.3 and 1.4 JVM's (they only surfaced under high concurrency), but I was told that the 1.5 JVM would better support .NET clients.
    Thanks...

    See
    http://www.simtel.net/product.php[id]95126[SiteID]simtel.net

  • Invocation API to launch an application

    Hi!
    Is it really possible to "start " a java VM from an application written in java?
    The page: http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/invocation.html describes some c++ code that shall do the job I guess....?....but I can't say that I understand everything of it....
    There isn't a simple step by step tutorial out there which describes how it shall be done?
    And what is the "Java application launcher" which the writers of JRE Install Notes 1.4.2 (http://java.sun.com/j2se/1.4.2/jre/install-windows.html) refer to at the bottom of the text?
    Final question: which jre shall I download and install - Windows Offline Installation, Multi-language?.....
    the tutorial http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/invocation.html talks about different JVM - jdk 1.1, Netscape ......
    Could someone please enlight me in this topic?
    Thanks

    First of all, I think the "launcher" mentioned in JRE doc is just a terminology and not a concrete entity. I suppose when you change the setting in Netscape or IE so that it can invokes the Java VM automatically each time there's Java code, that's the equivalent of a "launcher". That's why they say if you want to bypass this "launching" mechanism, you can use Invocation API to do it yourself (or invoke it from something other than Netscape or IE, say, your own self-written software).
    Normally when you're running a Java program, you're inside a JVM, and there's no need to "start" another VM, right? But, just for discussion purpose, if you really want to start another JVM in another "working" space, then yes, I think you can use the Invocation API to do just that. It's a bit awkward, since you'll have to use JNI to call out from Java to C++, then inside the C++ code, invoke JNI_CreateJavaVM() to create a new JVM and work in there. Then call jvm->DestroyJavaVM when you're done. Note that all JVM run from jvm.dll, so they may decide to recycle the very JVM that you were starting from (thus defeating our purpose). But in my opinion it most likely will not (be recycled) and will be a brandnew JVM.
    If you're not sure then try to use the JNI tutorial first. The invocation API is just a part of JNI. Once you're comfortable with calling Java -> C++, then things'll become much clearer.

  • Invocation API

    I am working with the invocation api from the tutorial. I do not want to set the path to the jvm.dll before running the exe. How can I dynamically load the dll. When I start the exe, immediately it popsup a message box saying that jvm.dll not found. Can anyone please help me out as to how to load the dll dynamically. All help is appreciated.
    Razi

    Try this:
    // runjava.cpp
    #include <windows.h>
    #include <jni.h>
    #define DOTRELEASE  "1.4" /* Same for 1.3.1, 1.3.2 etc. */
    #define JRE_KEY         "Software\\JavaSoft\\Java Runtime Environment"
    // typedefs for calls to jvm.dll
    typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
    typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);
    // globals
    JavaVMInitArgs vmArgs;
    JavaVM* jvm;
    JNIEnv* env;
    bool running=false;
    void LogError(const char * format,...)
        char    message[256];
        va_list args;
        va_start(args, format);
        vsprintf(message, format, args);
        va_end(args);
         printf("%s\n",message);          
    void LogWin32Error(const char * pTitle)
        PCHAR pBuffer;
        LONG  lError = GetLastError ( );
        FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                        NULL,
                        lError,
                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                        (char *)&pBuffer,
                        0,
                        NULL );
         LogError ("Win32 error: %s %s\n",pBuffer,pTitle);
        LocalFree ( pBuffer );
    bool GetStringFromRegistry(HKEY key, const char *name, unsigned char *buf, int bufsize)
        DWORD type, size;
        if (RegQueryValueEx(key, name, 0, &type, 0, &size) == 0
         && type == REG_SZ
         && (size < (unsigned int)bufsize))
              if (RegQueryValueEx(key, name, 0, 0, buf, &size) == 0)
                   return true;
        return false;
    bool GetPublicJREHome(char *buf, int bufsize)
        HKEY key, subkey;
        char version[MAX_PATH];
        /* Find the current version of the JRE */
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_KEY,0,KEY_READ,&key)!=0)
              LogError("Error opening registry key '" JRE_KEY "'\n");
              return false;
        if(!GetStringFromRegistry(key,"CurrentVersion",(unsigned char *)version, sizeof(version)))
              LogError("Failed reading value of registry key:\n\t"JRE_KEY "\\CurrentVersion\n");
              RegCloseKey(key);
              return false;
        if(strcmp(version, DOTRELEASE)!= 0)
              LogError("Registry key '" JRE_KEY "\\CurrentVersion'\nhas value '%s', but '" DOTRELEASE "' is required.\n", version);
              RegCloseKey(key);
              return false;
        /* Find directory where the current version is installed. */
        if(RegOpenKeyEx(key,version,0,KEY_READ, &subkey)!= 0)
              LogError("Error opening registry key '"JRE_KEY "\\%s'\n", version);
              RegCloseKey(key);
              return false;
        if(!GetStringFromRegistry(subkey, "JavaHome", (unsigned char *)buf, bufsize))
              LogError("Failed reading value of registry key:\n\t"JRE_KEY "\\%s\\JavaHome\n", version);
              RegCloseKey(key);
              RegCloseKey(subkey);
              return false;
        RegCloseKey(key);
        RegCloseKey(subkey);
        return true;
    jint JNICALL _vfprintf_(FILE *fp, const char *format, va_list args)
         LogError(format,args);
         return 0;
    void JNICALL _exit_(jint code)
         LogError("VM exited");
         exit(code);
    void JNICALL _abort_(void)
         LogError("VM aborted");
         abort();
    void LoadJVM(char * dir)
         HINSTANCE handle;
         JavaVMOption options[5];
         char JREHome[MAX_PATH];
         char JVMPath[MAX_PATH];                                        
         char classpathOption[MAX_PATH];
         char librarypathOption[MAX_PATH];
         if(!GetPublicJREHome(JREHome, MAX_PATH))
              LogError("Could not locate JRE");
              abort();
         strcpy(JVMPath,JREHome);
         strcat(JVMPath,"\\bin\\client\\jvm.dll");
        if ((handle=LoadLibrary(JVMPath))==0)
              LogError("Error loading: %s", JVMPath);
              abort();
        CreateJavaVM_t pfnCreateJavaVM=(CreateJavaVM_t)GetProcAddress(handle,"JNI_CreateJavaVM");
        if (pfnCreateJavaVM==0)
              LogError("Error: can't find JNI interfaces in: %s",JVMPath);
              abort();
         strcpy(classpathOption,"-Djava.class.path=");
         strcat(classpathOption,dir);
         strcat(classpathOption,";");
         strcat(classpathOption,JREHome);
         strcat(classpathOption,"\\lib");
         strcat(classpathOption,";");
         strcat(classpathOption,JREHome);
         strcat(classpathOption,"\\lib\\comm.jar");
         strcpy(librarypathOption,"-Djava.library.path=");
         strcat(librarypathOption,JREHome);
         strcat(librarypathOption,"\\lib");
         OutputDebugString("classpath option=");
         OutputDebugString(classpathOption);
         OutputDebugString("\n");
         OutputDebugString("librarypath option=");
         OutputDebugString(librarypathOption);
         OutputDebugString("\n");
         options[0].optionString=classpathOption;     
         options[1].optionString=librarypathOption;     
         options[2].optionString="vfprintf";
         options[2].extraInfo=_vfprintf_;
         options[3].optionString="exit";
         options[3].extraInfo=_exit_;
         options[4].optionString="abort";
         options[4].extraInfo=_abort_;
        vmArgs.version  = JNI_VERSION_1_2;
        vmArgs.nOptions = 5;
        vmArgs.options  = options;
        vmArgs.ignoreUnrecognized = false;
         //if(JNI_CreateJavaVM(&jvm, (void**)&env, &vmArgs)<0)
        if(pfnCreateJavaVM(&jvm,(void**)&env, &vmArgs)!=0)
              LogError("Could not create VM");
              abort();
    void main(int argc, char *argv[])
        char path[MAX_PATH];
        char drive[MAX_PATH];
        char file[MAX_PATH];
        char dir[MAX_PATH];
        char ext[MAX_PATH];
         jclass  cls;
         jmethodID mid;
         jobjectArray args;
         if(argc>=2)
              _splitpath(path,drive,dir,file,ext);
              LoadJVM(dir);
              if(env==NULL)
                   LogError("Could not load VM");
                   abort();
              if(GetModuleFileName(NULL,path,MAX_PATH)==0)
                   LogWin32Error("Getting module filename");
                   abort();
              cls=env->FindClass(argv[1]);
              if(cls==NULL)
                   LogError("Could not find class %s (or its superclass)",argv[1]);
                   exit(-1);
              mid=env->GetStaticMethodID(cls,"main","([Ljava/lang/String;)V");
              if(mid==NULL)
                   LogError("Could not find method 'main'");
                   exit(-1);
              args=env->NewObjectArray(argc-2,env->FindClass("java/lang/String"),NULL);
              if(args==NULL)
                   LogError("Could not create args array");
              for(int arg=0;arg<argc-2;arg++)
                   env->SetObjectArrayElement(args,arg,env->NewStringUTF(argv[arg+2]));
              env->CallStaticVoidMethod(cls,mid,args);
              jvm->DestroyJavaVM();
         else
              printf("Usage: runjava classname\n");
              exit(-1);
    //*****************************************************************************

  • 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)

  • JNI Invocation retry from JNI_ENOMEM leads to JNI_ERR

    We are using JNI Invocation from a C++ program to call from C++ to Java in a cross-platform Windows/Mac program. Usually this works great. Lately, though, we have been running into some issues on Windows XP (no problems so far on either Windows Vista or Mac OS X).
    In the problem cases, when we try to create the JVM, we get a JNI_ENOMEM error. This is odd since there appears to be plenty of memory available. We then try again, asking for less JVM memory. But that never seems to work - instead, we get a JNI_ERR message when retrying, at which point we are giving up. Asking for less memory does work when we do it the first time we try to create the JVM. But setting the maximum memory value that small would cause us to run out of JVM memory when handling larger data sets.
    Here's the basic code that we are using. Is there something obvious that we are doing wrong here when trying to create the JVM a second time?
    JavaVM *Jvm_mine;
    JNIEnv *Env_mine;
    JavaVMInitArgs vm_args;
    JavaVMOption options[3];
    char* classpathC;
    char* vmpathC;
    // Omitting classpathC and vmpathC assignment
    options[0].optionString = classpathC;
    options[1].optionString = "-Xms32m";
    options[2].optionString = "-Xmx512m"
    vm_args.version = JNI_VERSION_1_4;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = JNI_TRUE;
    // JNU_FindCreateJavaVM taken from Liang's JNI book
    CreateJavaVM_t pCreateJVM = JNU_FindCreateJavaVM(vmpathC);
    result = pCreateJVM(&Jvm_mine, (void**)(&Env_mine), &vm_args);
    // Usually this works, but sometimes on XP we get JNI_ENOMEM
    if (result == JNI_ENOMEM) {
        options[2].optionString = "-Xmx256m";
        result = pCreateJVM(&Jvm_mine, (void**)(&Env_mine), &vm_args);
        // We nearly always get a JNI_ERR value in result here
    }Pointers to debugging tools we could use to figure out why we are getting either the first JNI_ENOMEM error or the second JNI_ERR error would also be appreciated.
    Thanks for any assistance!
    Michael

    I also need to destroy the jvm from w/in a dll but i havent been able to get it to work properly. So far, everything ive read in the forum says just dont use it. but i dont want to just leave it hanging around.
    if you hear anything different, please share. :)
    txjump

  • Invocation API or Java Client Libraries

    Hi All,
    I want to invoke my short/long lived processes through my java code.
    Now, There are two ways to achieve this as i know .
    1. Invocation API (which I am using currently now)
    2. java client libraries
    Now my question is whether one can use java client libraries to invoke workbench processes through java code?
    If yes, is it better than Invocation API ?
    Thanks
    Abhiram

    Abhiram,
    You can invoke any service defined to LC (there are several exceptions for good reasons) whether they are out-of-the-box services or applications you have built yourself.
    In my opinion, your preference for invocation should be based upon the best fit for your existing Java classes. That's the beauty of the LC APIs. They give you some flexibility. The invocation APIs are nice for dealing with documents (PDF and native file formats). However, if your Java class(es) use Web Services then use the SOAP endpoint to call the LC process, for example. If performance is an issue and the Java class(es) run on the same host as LC, then use EJB.
    Steve

  • Debugging JVM crash via JNI Invocation

    Our software is causing a JVM crash with an EXCEPTION_FLT_STACK_CHECK error using the latest
    Sun 1.4.2 and 5.0 JVMs on Windows XP. No such error appears with 1.4 on Macintosh OS X.
    We start the JVM via JNI Invocation - our software is a plug-in for a standard Windows GUI program that
    requires a C++ interface. How can we get a crash dump or otherwise see what is going on when we
    crash? We don't have a chance to catch a Java exception. It seems to be crashing within a very generic
    call to the Xerces 2.6.2 XML parser.
    When we use the "-XX:+ShowMessageBoxOnError" option invoking the JVM, we do see a message box
    on the JVM error. Using the "-Xcheck:jni" option shows no problems. I tried viewing the JVM in jconsole,
    which worked nicely, but adding the "-Dcom.sun.management.jmxremote" option makes the crash
    go away.
    I feel like I've likely missed something obvious in my web and reference searches, but on the other hand
    JNI invocation information can be in short supply. This bug is 100% reproducible with a certain software
    and data setup.
    Thanks for any pointers and advice you can offer!
    Michael

    Thanks. Off list someone also pointed me to the Java troubleshooting guide at:
    http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf
    This is very helpful for giving instructions for creating a crash dump. Sun might be able to use it but I can't
    seem to get any response to my JVM bug report, so I'm looking for something that might help me figure
    out what the heck is going on. Is there a way to get a normal Java fatal error log via either
    -XX:+ShowMessageBoxOnError or -XX:OnError?
    Thanks again,
    Michael

  • ALERT from JNI invocation

    When I invoce the jvm from C++ with -verbose:jni I get the following :
    ***ALERT: JNI local ref creation exceeded capacity (creating: 17, limit: 16)
    at java.lang.System.initProperties(Native Method)
    at java.lang.System.initializeSystemClass(System.java:858)
    ***ALERT: JNI local ref creation exceeded capacity (creating: 18, limit: 16)
    at java.lang.System.initProperties(Native Method)
    at java.lang.System.initializeSystemClass(System.java:858)
    Can anyone explain what's happening ??

    Here's the code that brought up the ALERT :
    STDMETHODIMP CComToJava::CreateJavaVM()
         // TODO: Add your implementation code here
         JavaVM *jvm;
         JNIEnv *env;
         JavaVMOption options[3];
         JavaVMInitArgs vmArgs;
         vmArgs.version = JNI_VERSION_1_2;
         options[0].optionString = "-Djava.compiler=NONE"; /* disable JIT */
         options[1].optionString = "-Djava.class.path=c:\\prototyping\\jni\\classes"; /* user classes */
         options[2].optionString = "-verbose:jni"; /* print JNI-related messages */
         vmArgs.options = options;
         vmArgs.nOptions = 3;
         vmArgs.ignoreUnrecognized = TRUE;
         jint result = JNI_CreateJavaVM(&jvm,(void**) &env, &vmArgs);
         jclass jni2AtlClazz = env->FindClass("jni2atl/Jni2Atl");
         if(result == 0) {
              cout << "VM created" << endl;
         else {
              cout << "VM not created" << endl;
              exit(1);
         if(jni2AtlClazz == NULL) {
              cout << "Didn't find class" << endl;
              exit(1);
         return S_OK;
    /&ers

  • Why my Invocation API failed?

    I want to call Java in my C program,but I failed in my beginning.this is my simple code:
    #include "jni.h"
    #include "stdio.h"
    int main() {
    JavaVMOption options[2];
    JavaVMInitArgs vm_args;
    JavaVM *jvm;
    JNIEnv *env;
    long status;
    options[0].optionString = "-Djava.class.path=.";
    options[1].optionString = "-verbose:jni";
    memset(&vm_args, 0, sizeof(vm_args));
    vm_args.version = JNI_VERSION_1_4;
    vm_args.nOptions = 2;
    vm_args.options = options;
    status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    if (status == JNI_ERR) {
    printf("Can't create Java VM\n");
    else {
    printf("SUCCESS\n");
    return 0;
    the code pass the compiling,but when run,it always display:
    Can't create Java VM
    why?
    My JDK is in JBuilder9,and have jvm.dll file,one in E:\JBuilder9\jdk1.4\jre\bin\client,another in
    E:\JBuilder9\jdk1.4\jre\bin\server.and one is 1.1M,another is 2.7M.which one is right?

    Hallo,
    This topic has been discussed several times in this forum. Try searching the forum for JNI_CreateJavaVM[i]. The following code worked for me:
       JavaVMInitArgs vm_argsNew;
       vm_argsNew.version = JNI_VERSION_1_2;
       JavaVMOption options[3];
       options[0].optionString = "-verbose:gc";
       sprintf (classpath, "-Djava.class.path=%s", USER_CLASSPATH);
       options[1].optionString = classpath;
       options[2].optionString = "-Djava.compiler=NONE";
       vm_argsNew.options = options;
       vm_argsNew.nOptions = 3;
       vm_argsNew.ignoreUnrecognized = JNI_TRUE;
       /* Create the Java VM */
       void ** ppEnvVoid = reinterpret_cast <void **> (&a_pJNIenv);
       jint rc = JNI_CreateJavaVM(&a_pjvm, ppEnvVoid, &vm_argsNew);
        if (rc < 0)
           printf ("CreateJavaVm Failed\n");
           return RC_ERROR;
        }Unfortunately, the return codes from JNI_CreateJavaVM are not very informative! You need to keep playing until it works. I suspect that the [i]ignoreUnrecognized option could be important!

  • Invocation API: JFrame opens and closes immediatly when invoced.

    Hello,
    I'm sitting with an existing software, to which I would like to create a Java GUI to present calculation results in a nice way (simple editing, saving in different formats, etc.). The core is Fortran 77 and 90.
    Right now I'm trying to figure out how JNI works, and I have been able to make some C code show a Jframe. However, the JFrame disappears immediately if I don't make the runningThread.sleep() for some time, and I can't seem to find any GUI sample code. If I run it in NetBeans it stays open until I click the X.
    In the end I would like the GUI to be started from Fortran 90 when a user gives the plot command in the application console.
    In addition to the above problem, I would like a push in the right direction. What should I think about with this approach? Any common traps?
    This is how the test looks:
    Java code generated by NetBeans, where I just want to display a JFrame.
    public class JFrame extends javax.swing.JFrame {
        public JFrame() {
            initComponents();
        @SuppressWarnings("unchecked")
        private void initComponents() {
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("JFrameInvoced");
            setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            pack();
        @SuppressWarnings("static-access")
        public static void main(String args[]) throws InterruptedException {
            JFrame frameTest = new JFrame();
            frameTest.setVisible(true);
            Thread runningNow = Thread.currentThread();
            runningNow.sleep(1000);
    }C code from internet.
    #include <stdio.h>
    #include <jni.h>
    JNIEnv* create_vm() {
         JavaVM* jvm;
         JNIEnv* env;
         JavaVMInitArgs args;
         JavaVMOption options[1];
         int ret;
         /* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purposes of our example. */
         args.version = JNI_VERSION_1_4;
         args.nOptions = 1;
         options[0].optionString = "-Djava.class.path=D:\\Source\\Invocation_test";
         args.options = options;
         args.ignoreUnrecognized = JNI_FALSE;
         ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
         return env;
    void invoke_class(JNIEnv* env) {
         jclass helloWorldClass;
         jmethodID mainMethod;
         jobjectArray applicationArgs;
         jstring applicationArg0;
         //helloWorldClass = (*env)->FindClass(env, "InvocationHelloWorld");
         helloWorldClass = (*env)->FindClass(env, "JFrame");
         mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V");
         applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL);
         applicationArg0 = (*env)->NewStringUTF(env, "From-C-program");
         (*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);
         (*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs);
    int main(int argc, char **argv) {
         JNIEnv* env = create_vm();
         invoke_class( env );
    }

    sammen wrote:
    Can multithreading be a possible solution to this?Multithreading is certainly involved when you create a GUI using SWING, as SWING automatically creates a thread where all drawing and event handling is performed. Calculations and other longer tasks are performed outside that thread. This is done to avoid blocking the GUI during calculations.
    But first focus on the interface between the C program, where the calculations are performed, and the Java program, where the GUI should be located. Possible questions you should ask yourself are:
    - What data must be sent from the C part to the GUI?
    - What actions do I want to trigger from the C part, e.g. "create a plot"?
    - What actions do I want to trigger from the GUI to the C part, e.g. "redo calculations"?
    Then you could design the interface between those two. The multithreading performed by SWING has to be considered especially for the third question, as event handlers like "actionPerformed" are called from the SWING thread and should return quickly, just triggering the action, but not performing it. But those things are better discussed in the SWING forum.
    Martin

  • Java BPEL invocation API - NormalizedMessage.getPayloadString issue

    Hello,
    I'm trying to invoke a two-way (synchronous) BPEL process from with a J2EE application like so:
            NormalizedMessage requestMessage = new NormalizedMessage();
            requestMessage.addPart("payload", requestXml);
            Locator lctr = new Locator(domainId, password);
            IDeliveryService dService = (IDeliveryService) lctr.lookupService(IDeliveryService.SERVICE_NAME);
            NormalizedMessage responseMessage = dService.request(bpelId, operationId, requestMessage);I would like to receive the response as unparsed XML. I thought that would be possible using the following:
            String responsePayload = responseMessage.getPayloadString();but that returns null. responseMessage.getPayload() returns a Map from which I can successfully obtain the payload XMLElement, so the BPEL process is definitely working.
    Any ideas why getPayloadString is not working as I expect it to? Thanks.

    Perhaps try the BPEL forum here on OTN?
    -steve-

  • Access java properties from C++/JNI program

    Hello all,
    Is it possible to access the Java properties of a JNI VM from a C++ program?
    If so, could the code or process be explained to me.
    I want to be able to identify a specific VM that is retrieved by the JNI_GetCreatedJavaVMs
    call. I set a user property when the VM was created, and would like to verify its value
    before calling AttachCurrentThread.
    Thanks in advance.
    Mark

    Are you saying that you set a system property (via System.setProperty() or -D)?
    If so, just use the JNI invocation API to call System.getProperty().
    Without error checking, that looks something like this:bool isMySystem( JNIEnv* env ) {
      const string PropertyName = "IsMySystem";
      jclass systemClass = env->FindClass( "java/lang/System" );
      jmethodID getPropertyMethod = env->GetStaticMethodID( systemClass, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;" );
      jstring propertyNameString = env->NewStringUTF( PropertyName.c_str() );
      jstring propertyString = env->CallStaticObjectMethod( systemClass, getPropertyMethod, propertyNameString );
      if ( propertyString == 0 ) {
        return false;
      const char* property = env->GetStringUTFChars( propertyString, 0 );
      boolean isMine = ! strcmp( property, "Yes" );
      env->ReleaseStringUTFChars( propertyString, property );
      return isMine;
    }Using Jace, http://jace.reyelts.com/jace (a free, open-source toolkit), this would look more like:bool isMySystem() {
      String property = System::getProperty( "IsMySystem" );
      return property.isNull() ? false : prop == "Yes";
    }In the end, Jace ends up making all of the exact same calls, but you can see how much easier it is to use.
    God bless,
    -Toby Reyelts

Maybe you are looking for

  • Want to modify existing trigger

    I  have tried  to find  logon/logoff  details using  trigger program. 1)  trigger_logon  for  login time/date with user ans host information. 2)  trigger_logoff  for  login time. SQL> create or replace trigger tri_audit   2  AFTER LOGON ON DATABASE  

  • How to 'reset' a video?

    Hi, I have some swf-videos on an PDF-file and they stop on the last slide. Is there a option to jump automaticly back to the first slide and wait for a new start-click? Any advice would be great !! Greetings, Wolvo

  • Error 2147138480 in Set Scan Engine Mode to Actif

    Hi all, I'm fighting in front of this error which occur and does not want to go away (even after trying everything)... The error (-214713840) is happening when trying to set back the Scan Engine Mode to actif. It says: "The slave device could not be

  • Report  for cost center balance

    Hi is there std report through which i can view the balance of all the posting to a cost center for each company code, per cost element or where in a cost element, all the postingsfor all cost centers in a particular comapny code Regards Sanil Bhanda

  • Kerning doesn't look same in Photoshop

    Hi, Hope this finds you well. I am trying to export a file from InDesign to Photoshop. It's mostly type of all the same font. However, when I export it to Photoshop, the kerning on some -not all- of the type doesn't look the same/gets worse. Is there