Calling JVM from C native code

I'd like to call JVM from C native call.
I work in W2000 enviroment using GCC Cygnus compiler.
I followed JNI instructions.
I read in this forum there was a change in JDK, and instead of attaching javai.dll, jvm.dll must be attached.
Then I made a test using invoke.c example from JDK.
I built following .bat file:
gcc -c invoke.c -Id:\jdk1.3.1\include -Id:\jdk1.3.1\include\win32
DLLTOOL dllname jvm.dll def libjvm.def --output-lib d:\jdk1.3.1\jre\bin\classic\libjvm.a
c++ -o invoke.exe invoke.o -Ld:\jdk1.3.1\jre\bin\classic -ljvm
with libjvm.def :
EXPORTS
imp_JNI_GetDefaultJavaVMInitArgs@4
imp_JNI_CreateJavaVM@12
All seems to work fine, and invoke.exe is generated. But when trying to run it, I get a windows message telling me :
invoke.exe doesn't find the entry point to imp_JNI_CreateJavaVM@12 in jvm.dll.
What am I going wrong ?
Any calling convention issue ?
Thanks in advance. Ignasi Villagrasa.

Have a look at http://www.xraylith.wisc.edu/~khan/software/gnu-win32/. It has examples of how to use gcc, java JNI on cygwin and should work on all versions of Windows. It has the command line options for using dlltool.

Similar Messages

  • JVM Crashes in Native Code - JDK#1.4.2_10 for solaris-sparc

    Hi,
    We are facing irregular but quite frequent JVM crash in our Test environment. From the stacktrace it seems that JVM is crashing inside the native code. Can anyone help me in finding the cause of this problem please?
    Please find below the dump generated after JVM crash -
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # SIGBUS (0xa) at pc=0xfea32db4, pid=4695, tid=1
    # Java VM: Java HotSpot(TM) Client VM (1.4.2_10-b03 mixed mode)
    # Problematic frame:
    # C [libzip.so+0x2db4]
    --------------- T H R E A D ---------------
    Current thread (0x0003c2f0): JavaThread "main" [_thread_in_native, id=1]
    siginfo:si_signo=10, si_errno=151, si_code=3, si_addr=0xfe3a11cd
    Registers:
    O0=0xfe390000 O1=0x000111cc O2=0xffbfa350 O3=0x0003c4a0
    O4=0xff02aa10 O5=0xff008000 O6=0xffbfa1f0 O7=0xfea32d90
    G1=0x506f6c6c G2=0xff362a00 G3=0x0003c2f0 G4=0x00000066
    G5=0xf58d6cd8 G6=0x00000000 G7=0xff362a00 Y=0x00000000
    PC=0xfea32db4 nPC=0xfea32db8
    Top of Stack: (sp=0xffbfa1f0)
    0xffbfa1f0: 001de478 001deda8 fe3a11cc 00000000
    0xffbfa200: 00000000 fea40000 00000000 00000000
    0xffbfa210: 001de478 001deda8 0000506f 4f6d734e
    0xffbfa220: 80808080 01010101 ffbfa250 fea32ce0
    0xffbfa230: 00000000 2f3cbdc2 2f3cbdc2 f19cdfe8
    0xffbfa240: 0003c8b0 0003c8b0 ffbfa2b8 0000002b
    0xffbfa250: 001de478 ffbfa314 00000000 001deda8
    0xffbfa260: f206a1aa 00000043 0000ffff ff01f8a8
    Instructions: (pc=0xfea32db4)
    0xfea32da4: aa 02 40 0f d2 04 60 00 a4 02 00 09 a0 10 00 18
    0xfea32db4: d4 0c a0 01 95 2a a0 08 d0 0a 00 09 90 12 00 0a
    Stack: [0xffb7c000,0xffc00000), sp=0xffbfa1f0, free space=504k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [libzip.so+0x2db4]
    C [libzip.so+0x2ce8] ZIP_GetEntry+0xe0
    C [libzip.so+0x3488] Java_java_util_zip_ZipFile_getEntry+0x9c
    J java.util.zip.ZipFile.getEntry(JLjava/lang/String;)J
    J java.util.zip.ZipFile.getEntry(Ljava/lang/String;)Ljava/util/zip/ZipEntry;
    J java.util.jar.JarFile.getEntry(Ljava/lang/String;)Ljava/util/zip/ZipEntry;
    J sun.misc.URLClassPath$JarLoader.getResource(Ljava/lang/String;Z)Lsun/misc/Resource;
    J sun.misc.URLClassPath.getResource(Ljava/lang/String;Z)Lsun/misc/Resource;
    J java.net.URLClassLoader$1.run()Ljava/lang/Object;
    v ~StubRoutines::call_stub
    V [libjvm.so+0xc9ccc]
    V [libjvm.so+0xd6a34]
    C [libjava.so+0xdc38] Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2Ljava_secu
    rity_AccessControlContext_2+0x1c
    J java.security.AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)L
    java/lang/Object;
    J java.net.URLClassLoader.findClass(Ljava/lang/String;)Ljava/lang/Class;
    J java.lang.ClassLoader.loadClass(Ljava/lang/String;Z)Ljava/lang/Class;
    J sun.misc.Launcher$AppClassLoader.loadClass(Ljava/lang/String;Z)Ljava/lang/Class;
    J java.lang.ClassLoader.loadClass(Ljava/lang/String;)Ljava/lang/Class;
    J java.lang.ClassLoader.loadClassInternal(Ljava/lang/String;)Ljava/lang/Class;
    v ~StubRoutines::call_stub
    V [libjvm.so+0xc9ccc]
    V [libjvm.so+0xd1cec]
    V [libjvm.so+0xf43a0]
    V [libjvm.so+0x9ce34]
    V [libjvm.so+0x9c2c4]
    V [libjvm.so+0x9be3c]
    V [libjvm.so+0x9bbc4]
    V [libjvm.so+0xcbec8]
    V [libjvm.so+0xd0b84]
    j be.telenet.rts.oms.dbpoller.PollOmsNotificationTable.processDeleteOfAging(Lbe/telenet/rts/oms/dbpoller/OmsNotificationDataV
    O;)V+4
    J be.telenet.rts.oms.dbpoller.PollOmsNotificationTable.processOmsNotificationData(Ljava/util/Collection;)V
    J be.telenet.rts.oms.dbpoller.PollOmsNotificationTable.pollTable()V
    v ~RuntimeStub::osr_frame_return Runtime1 stub
    j be.telenet.rts.oms.dbpoller.ILMAdapter_NotifierPoller.main([Ljava/lang/String;)V+30
    v ~StubRoutines::call_stub
    V [libjvm.so+0xc9ccc]
    V [libjvm.so+0xdde98]
    V [libjvm.so+0x16791c]
    C [java+0x2f94] main+0x167c
    Thanks & Regards,
    Anuj

    Here's the exception I'm getting (slightly sanitized):
    Java Plug-in 1.4.2_10
    Using JRE version 1.4.2_10 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\tvalesky
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to
    load: class appls/DOLARS/user/Applet.class not found.
    java.lang.ClassNotFoundException: appls.DOLARS.user.Applet.class
         at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed:http://hostname.com/DOLARS.testing/dolars.testbed/classes/appls%2fDOLARS%2fuser%2fApplet%2fclass.class
         at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
         at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
         at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 7 more
    Exception: java.lang.ClassNotFoundException: appls.DOLARS.user.Applet.class

  • Not returning from the native code

    Hi,
    I am trying to access the native code using java applet. My java code seems to load the DLL(created using the VC++ 6.0) properly. Then when i call the native method called crypto, it does not seem to return from the nayive code . I am signing the applet and putting it a signed jar .Any suggestion is appreciated. I mite be wrong in the design too ...pleas ehelp. I am pasting the java code and the C code.
    cryptoJNI.java
    import java.awt.*;
    import java.io.*;
    import java.lang.*;
    import java.applet.*;
    public class cryptoJNI extends Applet {
         String uname=null;
         String b=null,ret=null;
         String a=null;
    public void init(){
              System.out.println("in init");
         public void dll_load(){
              b="before dll";
              System.loadLibrary("Msgimpl");
              a="after dll load";
         private native String crypto(String store);
    public void paint(Graphics g) {
              g.setColor(Color.blue);
              g.setColor(Color.magenta);
              load_dll();
              g.drawString(b, 5, 5);
              g.drawString(a, 15, 15);
              g.drawString("first call const", 25, 25);
              cryptoJNI app = new cryptoJNI();
              ret=app.crypto("My");
    g.drawString(ret, 75, 75);
              g.drawString("Signed 11", 120, 80);
              stop();
    CryptoJNI.c
    #define WIN32WINNT 0x0400
    #include <windows.h>
    #include <jni.h>
    #include <wincrypt.h>
    #define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
    #include "cryptoJNI.h"
    BOOL APIENTRY DllMain(HANDLE hModule,
    DWORD dwReason, void** lpReserved) {
    return TRUE;
    JNIEXPORT void JNICALL
    Java_CryptoJNI_crypto(JNIEnv * jEnv,jobject obj,jstring jstore) {
    //     char               name[256];
         const char *msg;
         msg = (*jEnv)->GetStringUTFChars(jEnv, jstore,0);
         //printf("Before context\n");
         //(*jEnv)->ReleaseStringUTFChars(jEnv, jstore,msg);
         return (*jEnv)->NewStringUTF(jEnv, msg);
    In my applet, i have some debugging statements that helps me verify that the Msgimpl.dll loads properly. When i invoke the app.crypto() it just "hangs". Please help
    Thanks,
    Vivek

    Hi,
    This is the exception that i am getting?? my cryptoJNIImp.c is is in the same directory as the my java file,c:\vivek work\signedcode. and i have added this to my path env variable...If u see the output, it executes the init() and then loads the Msgimpl.dll. So its got nothing do with loading a DLL. Any pointers on this..
    in init
    before loading dll
    After loading dll
    java.lang.UnsatisfiedLinkError: crypto
    at cryptoJNI.crypto(Native Method)
    at cryptoJNI.paint(cryptoJNI.java:65)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  • Calling jvm from c++ code fails the secnd time

    Hi all,
    i have a dll which calls java code thru jni.
    for the first time i am able to successfully call the jvm.
    when i execute 2nd time jvm crashes
    though i destroy the jvm for the first time.
    looks like it doesnot load all native method.
    below i have listed the verbose of jvm loading secnd time.
    please advice me if i need to use any technique in loading the jvm.
    thanks in advance
    [Dynamic-linking native method java.lang.Float.intBitsToFloat ... JNI]
    [Dynamic-linking native method java.lang.Double.longBitsToDouble ... JNI]
    [Dynamic-linking native method java.lang.Float.floatToIntBits ... JNI]
    [Dynamic-linking native method java.lang.Double.doubleToLongBits ... JNI]
    [Dynamic-linking native method java.lang.Object.registerNatives ... JNI]
    [Registering JNI native method java.lang.Object.hashCode]
    [Registering JNI native method java.lang.Object.wait]
    [Registering JNI native method java.lang.Object.notify]
    [Registering JNI native method java.lang.Object.notifyAll]
    [Registering JNI native method java.lang.Object.clone]
    [Dynamic-linking native method java.lang.Throwable.fillInStackTrace ... JNI]
    # HotSpot Virtual Machine Error, Internal Error
    # Please report this error at
    # http://java.sun.com/cgi-bin/bugreport.cgi
    # Error ID: 455843455054494F4E530E43505000DE
    # Problematic Thread: prio=139238232 tid=0x84c9b58 nid=0x0 runnable
    #

    Hallo,
    if I understand your problem correctly, you are creating the JVM, doing something, calling DestroyJavaVM() and then creating the JVM once more. You cannot do that! See: http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html#DestroyJavaVM . The solution is just to create the JVM once, when you first need it. You can then reuse it as offen as you want.

  • Calling JVM from outside

    Hello!
    A question of possibly not a common nature: are there any ways I can ask a JVM to run a specific Java code.
    For example, when MS IE encounters an applet, it somehow instructs JVM to start up, provide an environment for applet's intercommunication with IE, and execute the applet.
    How can I do the same thing in my WinXP program - i.e. to make JVM start up and execute something, possibly - applet, or a kind of bean, or...?
    Or, a thinner task: there is a file 'CCC.class' with class CCC containing static member function bool LaunchAnthraxMissile(int targetX, int targetY);
    Is there any way for me in my external program (possibly, in C++) to execute this function and examine a result? (without, of course, launching java interpreter with CreateProcess :) )
    Thanks,
    Slicer

    Is there any way for me in my external program (possibly, in C++) You could use JNI.
    However it is probably just easier to do a operating system call where the execution string is "java MyClass".

  • Call script from script; exit code issues

    I have verified in a very simple pair of scripts that I can feed an exit code back to the calling script. My "Parent" test is little more than 
    powershell.exe -file "$ScriptPath\child.ps1"
    Write-Host "$LASTEXITCODE!!!"
    and the child script is just
    Exit 1
    And that Write-host comes back correctly. I have even tried it with two different child scripts, with different rerun codes, being called from Parent back to back. All good.
    However, in a more complicated script, where the child script has conditional exits, I am getting 0 all the time. The conditional looks like this
    if ($Global:MemberofSet) {
        if ($Global:ErrorOccured) {
            Write-Host '1'
            Exit 1
        else {
            Write-Host '0'
            Exit 0
    And even when the 1 echoes, I still get a $LASTEXITCODE of 0.
    Is there some known issue here that I am not aware of? Using PS 2.0, FWIW.
    Thanks!

    Um, no, more that I remmed out
    [CmdletBinding()] at the top of each child script and with no other changes everything is working exactly as it should. Not sure why it worked, but I am certainly not imagining it.
    For shits and giggles I also added the binding in my little test script set, and that is now broken,
    with no other changes. I really hadn't created a good test obviously, but I wasn't expecting binding to matter. Would love to hear an explanation as to why it would
    For anyone wanting to see the behavior, these are the three test scripts, and you run the Arch script. With binding enabled DTV will show 1, but return 0. Rem the
    bindings and DTV will correctly return 1. I also tested RVT to not be MemberofSet, so -1 is returned, and $LASTEXITCODE shows a wonky number as expected given the bug in 2.0 and negative return codes. 
    NOTE: In the test the argument in the child scripts is not used, it's just there to avoid the error you otherwise get when binding. In my "live" code the
    arguments are mandatory and used.
    Arch_2015.ps1
    powershell.exe -file "RVT_2015.ps1"
        Write-Host "$LASTEXITCODE!"
    powershell.exe -file "DTV_2015.ps1"
        Write-Host "$LASTEXITCODE!"
    DTV_2015.ps1
    [CmdletBinding()]
    Param ([string]$Mode)
    $Global:MemberofSet = $True
    $Global:ErrorOccured = $True
    if ($Global:MemberofSet) {
        if ($Global:ErrorOccured) {
            Write-Host 'DTV 1'
            Exit 1
        else {
            Write-Host 'DTV 0'
            Exit 0
    else {
        Write-Host 'RVT -1'
        Exit -1
    RVT_2015.ps1
    [CmdletBinding()]
    Param ([string]$Mode)
    $Global:MemberofSet = $True
    $Global:ErrorOccured = $False
    if ($Global:MemberofSet) {
        if ($Global:ErrorOccured) {
            Write-Host 'RVT 1'
            Exit 1
        else {
            Write-Host 'RVT 0'
            Exit 0
    else {
        Write-Host 'RVT -1'
        Exit -1

  • Calling JVM from C++

    My biggest dream at the moment is to start Java class "halllo world" from C++. Following environments are being used:Windows 2000, Visual C++ and JBuilder4.0
    I�m running out of ideas and it seems to me the more I look for a solution the more contradictory informations I get. In book CORE JAVA (Sun) they say that i need jni.h .O.K. Included...They also say for windows jvm.dll library is needed..I tried it too ..I have put path to this library in all possible paths in Visual c++..Doesn�t work..I have also made include of jvm.h but then I get errors in windows.h???? on a few pages in internet (ibm..) I have found that in this case for Windows javai.lib is needed..? What�s that suppose to mean???? This library doesn`t exist in JBuilder or anywhere else.
    I�m stuck with this problem for two weeks,working on my diploma and loosing nervs...So please if somebody has at least new ideas or even better knows the solution contact me...Thanks

    I forgot to add what is my biggest problem: Functions as JNI_CreateJavaVM...are not being recognized..I m getting linking errors :Unresolved symbol....JNI_CreateJavaVM...and so on and so on...
    Thanks again ...

  • JVM dies when JNI native code causes a SIGABRT from assertions

    Hi,
    I am wondering whether there is a way to prevent the JVM from dying when the JNI native code hits an assertion.
    #include "NativeTest.h"
    #include <assert.h>
    JNIEXPORT jstring JNICALL Java_NativeTest_sayHello (JNIEnv *env, jobject thisobject, jstring js)
    assert(0);
    return js;
    Calling this code from Java through JNI causes a SIGABRT when assert(0) is hit. This causes the java program to terminate. Is there a way for the JVM to recover from the SIGABRT from the native code?

    929919 wrote:
    I am wondering whether there is a way to prevent the JVM from dying when the JNI native code hits an assertion.There is no way to prevent the VM from exiting if native code does anything that causes an exit.
    An assertion is only one way that can happen.
    So to prevent the VM from exiting - don't run native code. The safe way to execute OS native library is to do the following.
    1. Wrap the library in an executable.
    2. Create a communications API for the executable.
    3. Manage the executable via Java Runtime.exec/ProcessBuilder.
    4. Talk to the executable using the communications API from 2 in the java code.
    The above is safe because if the library exits it exits the executable, not the VM.

  • Increase JVM heap size when calling it from C++

    I have a program that loads images and only works properly increasing heap.
    java McVImg
    gives me an Out of memory error.
    java -Xmx120M McVImg
    works fine.
    If I want to call JVM from a C++ program using Java native interface,
    How should I increase JVM heap ?
    Thanks in advance. Ignasi Villagrasa.

    I'm trying to do what you told me and it doesn't work.
    I show the C++ code I'm using:
    void JavaParam::LoadJVM()
         JavaVMInitArgs vm_args;
         JavaVMOption options[2];
    jint res;
         vm_args.version = JNI_VERSION_1_2;
    JNI_GetDefaultJavaVMInitArgs(&vm_args);
         if (res < 0)
    fprintf(stderr, " Requested version is not supported\n");
              fputs ("Requested version is not supported\n",traza);
              fflush(traza);
    exit(-1);
         //Establecemos classpath
         //Atencion el classpath ser� el jar
         //options[0].optionString = "-Djava.class.path=..";
         options[0].optionString = "-Djava.class.path=..\\mcjava.jar";
         options[1].optionString = "-Xmx120M";
         //Nuevos argumentos
    vm_args.options=options;
         vm_args.nOptions = 2;
         vm_args.ignoreUnrecognized = JNI_FALSE;
         //Creamos Maquina Virtual Java
    res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
    if (res < 0)
    fprintf(stderr, "Can't create Java VM: %d\n",(int)res);
              fprintf(traza, "Can't create Java VM RES: %d \n",(int)res);
              fflush(traza);
    exit(1);
         jvm_creada = 1;
    Is that right ?
    Thanks in advance. Ignasi Villagrasa.

  • Setting native code from a class of a class passed in...

    I hope this makes sense, and its probably a stupid question but here it goes.
    I have a native function that takes in a java class. I can call the getters of this class from the native code to get values to fill out my c structure just fine, but conceptually I am not 100% how to call the getters of a class that is part of the other class I passed in. Basically i have something like this:
    the java call to the native being:
    public native void setJSource(JSource theSource);
    JNIEXPORT void JNICALL Java_AbfaRegion_setJSource
      (JNIEnv *env, jobject thisObj, jobject someVarsObj)
              jclass clazz;
              jmethodID mid;
              jint val;
              clazz = (*env)->GetObjectClass(env,someVarsObj);
              mid = (*env)->GetMethodID(env,clazz, "GetHeight", "I");
              val = (*env)->CallIntMethod(env,someVarsObj, mid);
              //put val into my struct
              mid = (*env)->GetMethodID(env,clazz, "GetWidth", "I");
              val=(*env)->CallIntMethod(env,someVarsObj, mid);
              //put val into my struct
    }I know how to do this...but what if I had a class say:
    class myClass
        JSource theSource; //has its own getters and setters like GetHeight
        int someVal;
        double anotherVal;
        public native void setMyClass(myClass theClass)
        int GetSomeVal()
          return this.someVal;
        int GetAnotherVal()
          return this.anotherVal;
        void SetSomeVal(int iSomeVal) 
          this.someVal=iSomeVal;
        void SetAnotherVal(double dAnotherVal)
          this.anotherVal=dAnotherVal;
    }and then suppose in the native setMyClass I would like to get the height of the jsource of myclass, how can i do that in native code, do I have to use findclass or something?
    Thanks for any help here, sorry if its a dumb question..
    -Shane

    For any class whose methods you are going to call, you need to first get a reference to the "class" record. So if you have an outer class, and have looked up its class record, and called a getter, and been returned an object (phew!):
    You need to now look up the class for the inner object; you can then look up the the methods and call them.
    JNI supports two ways to look up class:
    FindClass, where the key argument is the fully-qualified class name.
    GetObjectClass, where the key argument is an object reference.

  • Calling Java from C++  using JNI

    I have been looking into JNI, and I ran sample where the Java calls Native c/c++ methods. Now to do it the other way, having C/C++ to call Java method by passing argument and getting the results back, I think I need to follow the example in Chapter 5 sun, which is creating JVM in the native code, accessing the Java class and method, and then finally calling the Java method.
    First I like to know if I'm right above, and second if I need to pass a C++ class as the argument to the Java method and then the result from the method is Java class, what would be the best way to do? I know I need some to convert the class type some how.
    Thanks,
    Eli

    Are you also wanting to launch Java from C++? Unzip JAVA_HOME/src.zip and look at the source code for java.exe
    If you have native called by a Java object then you can call any non native method in the Java object from the C/C++ side. Example Java method, reportCurrentStagePosition :
        public void reportCurrentStagePosition (int fault, double x, double y, double z, double &#966;)
            if (fault == 0)
                reportCurrentStagePosition (x, y, z, &#966;);
            else
                faultMessage = "Stage Positioning Fault: X="+eFormat(x)+", Y="+eFormat(y)+", Z="+eFormat(z)+", phi="+eFormat(&#966;);
                System.out.println ("***Aero Fault Message: "+faultMessage);
        public native long moveLinearXYZPhiAxes() throws PositionException;Then from the native side of moveLinearXYZPhiAxes the obj is the calling object and has the reportCurrentStagePosition method
    JNIEXPORT jlong JNICALL Java_com_hypernex_goniometer_AerotechWrapperN_moveLinearXYZPhiAxes (JNIEnv *env, jobject obj)
         jmethodID jReportPositions = env->GetMethodID(env->GetObjectClass(obj), "reportCurrentStagePosition", "(IDDDD)V");
         if (jReportPositions == NULL)
              printf ("***ERROR*** about to call jReportPositions but it is NULL ***\n");
         else
             env->CallVoidMethod (obj, jReportPositions, 0, xFeedBack, yFeedBack, zFeedBack, phiFeedBack);
    }Since reportCurrentStagePosition returns a void you use the CallVoidMethod of env. The "(IDDDD)V" is the signature of the method. If it is there GetMethodID returns a non null.

  • "ReferenceError: "myIpAddr"  is not defined, when call JavaScript from java

    Hi developers,
    My java application was trying to issue a http request via proxy auto-config. So, I did below jobs
    1. Read URL of *.pac from registry
    2. Call FindProxyForURL from java, the code is like below
                   ScriptEngineManager factory = new ScriptEngineManager();
                   ScriptEngine engine = factory.getEngineByName("JavaScript");
                   engine.eval(autoProxyScript);
                   Invocable inv = (Invocable) engine;
                   Object obj = inv.invokeFunction("FindProxyForURL",
                             "http://java.sun.com/",
                             "java.sun.com");
    However, I got "ReferenceError: "myIpAddress" is not defined
    I can not change the script on server to add a function like "myIpAddress", I am wordering why IE or mozilla can call it successfully and get proxy server, while Java failed to do that.
    I got a ugly solution by calling "pacparser" by jni. But I really hope I can get a better solution.

    A .pac file is a JavaScript, but it requires some functions to be defined in the executing context to work (i.e. you must define those).
    From the example on the Wikipedia page there's at least "shExpMatch" and "isInNet". "myIpAddress" seems to be another such candidate.

  • Exception while calling BPEL from Java Class

    Hi All,
    I am trying to call BPEL from my Java Code. but i am getting following exception.
    java.lang.Exception: Failed to create "ejb/collaxa/system/DomainManagerBean" bean; exception reported is: "javax.naming.NameNotFoundException: ejb/collaxa/system/DomainManagerBean not found
         at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:52)
         at javax.naming.InitialContext.lookup(InitialContext.java:351)
         at com.oracle.bpel.client.util.BeanRegistry.lookupDomainManagerBean(BeanRegistry.java:218)
         at com.oracle.bpel.client.Locator.getDomainAuth(Locator.java:975)
         at com.oracle.bpel.client.Locator.<init>(Locator.java:73)
         at callbpel.CallBPEL.main(CallBPEL.java:40)
         at com.oracle.bpel.client.util.BeanRegistry.lookupDomainManagerBean(BeanRegistry.java:232)
         at com.oracle.bpel.client.Locator.getDomainAuth(Locator.java:975)
         at com.oracle.bpel.client.Locator.<init>(Locator.java:73)
         at callbpel.CallBPEL.main(CallBPEL.java:40)
    Process exited with exit code 0.
    Following is my java code.
    package callbpel;
    import com.collaxa.cube.util.GUIDGenerator;
    import com.collaxa.xml.XMLHelper;
    import com.oracle.bpel.client.Locator;
    import com.oracle.bpel.client.NormalizedMessage;
    import com.oracle.bpel.client.delivery.IDeliveryService;
    import java.util.Hashtable;
    import java.util.Map;
    import com.oracle.bpel.client.ServerException;
    import java.rmi.RemoteException;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import org.w3c.dom.Element;
    public class CallBPEL {
    public CallBPEL() {
    public static void main(String[] args) {
    CallBPEL callBPEL = new CallBPEL();
    Hashtable env;
    try {
    env = callBPEL.getInitialContext();
    String xml = "<ssn xmlns=\"http://services.otn.com\">" + "1234" + "</ssn>";
    Locator locator = new Locator("default",env);
    IDeliveryService deliveryService = (IDeliveryService)locator.lookupService
    (IDeliveryService.SERVICE_NAME );
    NormalizedMessage nm = new NormalizedMessage();
    nm.addPart("payload", xml);
    try {
    deliveryService.post("JavaCallingBPEL", "initiate", nm);
    System.out.println("BPELProcess HelloWorld executed!<br>");
    } catch (ServerException e) {
    e.printStackTrace();
    } catch (RemoteException e) {
    e.printStackTrace();
    } catch (NamingException e) {
    e.printStackTrace();
    } catch (ServerException e) {
    e.printStackTrace();
    private static Hashtable getInitialContext() throws NamingException {
    Hashtable env = new Hashtable();
    env.put("orabpel.platform","ias_10g");
    env.put("java.naming.factory.initial","com.evermind.server.rmi.RMIInitialContextFactory");
    env.put("java.naming.provider.url","opmn:ormi://localhost:6004:oc4j_soa/orabpel");
    env.put("java.naming.security.principal","oc4jadmin");
    env.put("java.naming.security.credentials","welcome1");
    return env;
    I am breaking my head since last two days. i dont know whats the problem. i have included almost all the jars in class path.
    Can anybody help me in this.
    any help is appreciated.
    Thanks,
    Nimisha

    Hi all,
    I have solved above problem but run into some other exception below
    Dec 22, 2008 12:51:34 PM oracle.j2ee.rmi.RMIMessages EXCEPTION_ORIGINATES_FROM_THE_REMOTE_SERVER
    WARNING: Exception returned by remote server: {0}
    com.evermind.server.rmi.RMIConnectionException: Disconnected: com.oracle.bpel.client.AbstractIdentifier; local class incompatible: stream classdesc serialVersionUID = 3174123903773674079, local class serialVersionUID = -4389351842028223514
         at com.evermind.server.rmi.RmiCallQueue.notifyQueuedThreads(RmiCallQueue.java:70)
         at com.evermind.server.rmi.RMIClientConnection.notifyQueuedThreads(RMIClientConnection.java:154)
         at com.evermind.server.rmi.RMIClientConnection.resetState(RMIClientConnection.java:128)
         at com.evermind.server.rmi.RMIConnection.receiveDisconnect(RMIConnection.java:233)
         at com.evermind.server.rmi.RMIClientConnection.receiveDisconnect(RMIClientConnection.java:140)
         at com.evermind.server.rmi.RMIConnection.handleOrmiCommand(RMIConnection.java:208)
         at com.evermind.server.rmi.RMIClientConnection.processReceivedCommand(RMIClientConnection.java:222)
         at com.evermind.server.rmi.RMIConnection.handleCommand(RMIConnection.java:152)
         at com.evermind.server.rmi.RMIConnection.listenForOrmiCommands(RMIConnection.java:127)
         at com.evermind.server.rmi.RMIConnection.run(RMIConnection.java:107)
         at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:819)
         at java.lang.Thread.run(Thread.java:595)
    Any Idea?
    Thanks,
    Nimisha
    Edited by: user649974 on Jan 6, 2009 10:50 AM

  • Calling existing C++ dll from native code causes an ACCESS_VIOLATION

    Hi everyone,
    I'm having issues creating a Java app to call an existing c++ DLL. I've done extensive searching for a solution and found lots of goodies, but nothing to fix my problem yet.
    I've gone through the JNI tutorial and created my java class, used javah, and created my native code according to the tutorial.
    I'm new to dealing with DLLs so I'm not sure if there are some steps that I'm not taking.
    The issue comes when I run the program. I get an EXCEPTION_ACCESS_VIOLATION.
    the DLL I'm trying to call makes a call to a device on the USB port. I also have the source code and header files for the DLL but thought it would be easier to just have to deal with the already built DLL.
    After putting some print statements in the native function, the violation comes when I try to call the function in the external DLL. The DLL itself loads correctly (as far as I know).
    Here my native method that will load the external dll. I got the code to call the DLL method from:
    http://goff.nu/techarticles/development/cpp/calldll.html
    JNIEXPORT void JNICALL
    Java_OCPMControl_OCPMSetPixelCount (JNIEnv *env, jobject obj, jint pixelCount)
    //load the dll
    HINSTANCE ocpmSerialDLL = LoadLibrary("OCPMSerialDLL");
    /* get pointer to the function in the dll*/
    FARPROC myDLLFunction = GetProcAddress(HMODULE(ocpmSerialDLL), "OCPMSetPixelCount");
    /* Define the Function in the DLL for reuse. This is just prototyping
    * the dll's function. A mock of it. Use "stdcall" for maximum compatibility.
    typedef void (__stdcall * FUNC)(enum ePixelNum);
    FUNC MyFunction;
    MyFunction = FUNC(myDLLFunction);
    printf("Calling function\n");
    /* The actual call to the function contained in the dll */
    MyFunction(PIXEL256);
    /* Release the Dll */
    FreeLibrary(ocpmSerialDLL);
    When I run the program, I get the following error:
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x182
    91E6B
    Function=[Unknown.]
    Library=C:\sun\MyJava\ocpm\src\OCPMSerialDLL.dll
    NOTE: We are unable to locate the function name symbol for the error
    just occurred. Please refer to release documentation for possible
    reason and solutions.
    Current Java thread:
    at OCPMControl.OCPMSetPixelCount(Native Method)
    at OCPMControl.getData(OCPMControl.java:167)
    at OCPMService.main(OCPMService.java:46)
    Dynamic libraries:
    0x00400000 - 0x00406000 c:\sun\j2sdk1.4.2_03\bin\java.exe
    0x77F80000 - 0x77FFD000 C:\WINNT\system32\ntdll.dll
    0x7C2D0000 - 0x7C332000 C:\WINNT\system32\ADVAPI32.dll
    0x7C570000 - 0x7C628000 C:\WINNT\system32\KERNEL32.DLL
    0x77D30000 - 0x77DA1000 C:\WINNT\system32\RPCRT4.DLL
    0x78000000 - 0x78045000 C:\WINNT\system32\MSVCRT.dll
    0x08000000 - 0x08138000 c:\sun\j2sdk1.4.2_03\jre\bin\client\jvm.dll
    0x77E10000 - 0x77E75000 C:\WINNT\system32\USER32.dll
    0x77F40000 - 0x77F7E000 C:\WINNT\system32\GDI32.DLL
    0x77570000 - 0x775A0000 C:\WINNT\system32\WINMM.dll
    0x10000000 - 0x10007000 c:\sun\j2sdk1.4.2_03\jre\bin\hpi.dll
    0x007C0000 - 0x007CE000 c:\sun\j2sdk1.4.2_03\jre\bin\verify.dll
    0x007D0000 - 0x007E9000 c:\sun\j2sdk1.4.2_03\jre\bin\java.dll
    0x007F0000 - 0x007FD000 c:\sun\j2sdk1.4.2_03\jre\bin\zip.dll
    0x18270000 - 0x1827E000 C:\sun\MyJava\ocpm\src\OCPMNative.dll
    0x18290000 - 0x182AA000 C:\sun\MyJava\ocpm\src\OCPMSerialDLL.dll
    0x68120000 - 0x681A1000 C:\sun\MyJava\ocpm\src\instrsup.dll
    0x76B30000 - 0x76B6E000 C:\WINNT\system32\comdlg32.dll
    0x70A70000 - 0x70AD5000 C:\WINNT\system32\SHLWAPI.DLL
    0x71710000 - 0x71794000 C:\WINNT\system32\COMCTL32.DLL
    0x782F0000 - 0x78538000 C:\WINNT\system32\SHELL32.DLL
    0x77920000 - 0x77943000 C:\WINNT\system32\imagehlp.dll
    0x72A00000 - 0x72A2D000 C:\WINNT\system32\DBGHELP.dll
    0x690A0000 - 0x690AB000 C:\WINNT\system32\PSAPI.DLL
    Heap at VM Abort:
    Heap
    def new generation total 576K, used 140K [0x10010000, 0x100b0000, 0x104f0000)
    eden space 512K, 27% used [0x10010000, 0x10033368, 0x10090000)
    from space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)
    to space 64K, 0% used [0x100a0000, 0x100a0000, 0x100b0000)
    tenured generation total 1408K, used 0K [0x104f0000, 0x10650000, 0x14010000)
    the space 1408K, 0% used [0x104f0000, 0x104f0000, 0x104f0200, 0x10650000)
    compacting perm gen total 4096K, used 1012K [0x14010000, 0x14410000, 0x1801000
    0)
    the space 4096K, 24% used [0x14010000, 0x1410d1f0, 0x1410d200, 0x14410000)
    Local Time = Wed May 12 10:53:56 2004
    Elapsed Time = 10
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.4.2_03-b02 mixed mode)
    # An error report file has been saved as hs_err_pid2120.log.
    # Please refer to the file for further information.
    Is there something else I have to do to tell the JVM that the external DLL call isn't an Access Violation?
    Would it be easier to use the source files instead?
    Thanks to anyone who can help me out here!
    Scott Campbell

    Thanks,
    The problem has been solved. I wasn't linking the dll properly to access the external DLL and thus, my native DLL was looking for methods that it didn't know how to find. which was easily solved by adding a few options when creating my native dll.
    Here is the link I found to solve the problem incase anyone else has issues like this. It is regarding implicit v.s. explicit linking to external DLLs in using visual C++.
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_link_an_executable_to_a_dll.asp
    Scott.

  • Calling native code from Flex

    I was wondering, is there any way to call native code from Flex?
    Currently, we're writing browser plugins in order to call native code from a Flex application. However, it would be nice to be able to call native code directly from Flex, so that we could write it only per-platform, as opposed to currently per-platform-per-browser.

    In general, the sandbox does not allow you to access native code from Flex.
    I believe you can use Merapi, but perhaps only for AIR:
    http://www.merapiproject.net/
    You might be able to code around the Flex sandbox, but it would be a ton of work.
    If this post answers your question or helps, please mark it as such.

Maybe you are looking for