How call native method without code modification

"How to access third party's C API from Java Using JNI without modifying the C code"

Unfortunately, the only way I know of doing this is to use a pass-through DLL that you write. Logically it
looks like this:
Java App (written by you)
|
v
Java native methods (written by you)
|
v
JNI DLL (written by you)
|
v
3rd party DLL
It adds a little bit of overhead, but it's not too big of a deal. Check out the JNI tutorial on how to write this.
Bryan

Similar Messages

  • Calling native methods in a package

    Hi!
    We have a problem when calling native methods in a class which is in a package. As you can see from the code below we have a class making an instance of a class<testBando> which makes a instance of another class<Bando> which contains the native methods. When running the program we get the error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: initialize
    at test2.Bando.initialize(Native Method)
    at test.testBando.<init>(testBando.java:10)
    at Main.main(Main.java:5)
    When we take the class that calls the native methods out of any package every thing works fine! Can you not call native methods inside a package or what are we doing wrong?
    // testBando.java
    package test;
    import test2.*;
    public class testBando {
    Bando b;
    public testBando() {
         b = new Bando();
         b.initialize();
    // Bando.java
    package test2;
    public class Bando {
    public native void initialize();
    static {
         System.loadLibrary("bando");
    // Main.java
    import test.*;
    public class Main {
    public static void main(String[] args) {
         new testBando();

    I suspect that your problem is that you have not
    regenerated the signature when you placed the native
    method's object in a package. Or same result but different sourc:
    -package name was changed and it wasn't regen'd
    -javah was run incorrectly (which gens the signatures with no package name.)

  • Calling native Objective C code from Java Script

    Hi,
    I want to call native objective C code from Java script.
    I know one way by using : webView:shouldStartLoadWithRequest:navigationType
    Is there another way of doing same?
    Thanks,
    Ganesh Pisal
    Vavni Inc

    Are any of those threads calling java code? If yes then are you calling the Attach method?

  • Urgent - How to call native methods from J2ME

    Hi,
    I have to do some very heavy processing work, so I have my code written in C. And now I want these native functions to be called from a J2ME application. I had thought this was not possible and J2ME did not support something like JNI as J2SE did.
    However, when contacted with Sun Technical Support we were advised to use KNI in J2ME. I went through the KNI documentation and did not find any example to do so.
    On reading about it I understood that it cannot be implemented by developers as the native functions if any using KNI should be implemented while compiling the KVM.
    I would like to know whether my understanding is correct, or is it possible to call native functions from J2ME. Say I would like to have my native functions called from J2ME and run it on my Nokia N73 or other such phones.
    Experts please clear this.
    Regards,
    Kamalakshan

    Hi,
    You are right in your assumptions regarding KNI. Here is some related thread that might also help. There has been [some work|http://developer.symbian.com/main/downloads/papers/MIDlet_Native_Services_Framework/MIDlet_Native_Services_Framework_v1.1.zip] done in accessing native services through a MIDlet.
    Mihai

  • Call native methods from windows dll

    Hello all,
    I want to call BlockInput method from User32.dll. My source code looks something like this:
    public class User32Dll_1 {
         static {
              try {
                   System.loadLibrary("User32");
              catch (Exception ex)
                   ex.printStackTrace();
         public static void main(String[] args) throws UnsatisfiedLinkError {
              BlockInput (true);
         /** @param b
         * @dll.import("USER32")*/
         private static native boolean BlockInput(boolean bBOOL);
    And the problem is that I get the following exception:
    java.lang.UnsatisfiedLinkError: BlockInput
         at User32Dll_1.BlockInput(Native Method)
         at User32Dll_1.main(User32Dll_1.java:27)
    Exception in thread "main"
    Can someone provide me a solution for this?
    Thank you in advance!

    can't do
    use JACOB
    http://danadler.com/jacob/
    or
    http://www.ezjcom.com/

  • Newbie Q'n -- Calling class methods without instantiation

    Hello All,
    I would like to know how is it possible to call methods within a class without instatiating the class.
    For instance consider the following statement:
    String x = Integer.toString(10);
    Here there we are calling the toString() function of "Integer" class without instantiating it. How is it possible?? How does the JVM call the toString() function when there is no Integer object defined in my program?? Can the same functionality achieved for user created classes ??
    Can anyone explain ??
    If this appears as a trivial question, please forgive me.
    Thanks in advance,
    Arun

    String x = Integer.toString(10);
    Here there we are calling the toString() function of
    "Integer" class without instantiating it. How is it
    possible?? How does the JVM call the toString()
    function when there is no Integer object defined in my
    program?? Can the same functionality achieved for user
    created classes ?? It isn't possible, and its not happening in your example either:
    toString() is an instance method. toString(int) and toString(int, int) are class (static) methods.
    You might see documentation referring to a toString (notice no "()" at the end) method. When you do, it should usually be clear from the context which particular method is being referred to.
    Such confusion might well have been avoided if the original API designers had thought to call the methods something different (perhaps format?), but they didn't (in fact, toString(int) seems rather pointless).

  • Calling varargs method without varargs parameter.

    Hello
    I really appreciate your help on clarifying the following problem.
    1) I have method signature as
    public User validateUser(User usr, boolean isLogin,Object...args)
    2) When I call this method as
    obj.validateUser(usrObject,true);
    In windows environment, the method implementation specified in 1) is called and no issues.
    But, when the same code is deployed on linux, I get the following error
    java.lang.NoSuchMethodError: com.mysubpackage.dao.myobject.*validateUser(Lcom/startf orce/system/User;Z)Lcom/startforce/system/User;*
    Please let me know, if there is any known incompatibility issue out there between windows and linux.
    Thanks
    Muthu

    Hi Jverd
    You are right! I think I worked too much and got lost somewhere, to prove me wrong I wrote the following test class and ran on both linux and windows and produced the same result (as it should). -:) Thanks all of you for responding.
    public class VarArgsTest {
          * @param args
         public static void main(String[] args) {
               VarArgsTest test = new VarArgsTest();
               System.out.println("\nCalling varArgs with two parameter as test.printVarArgs(\"I am Param1 Value\", \"I am Param2 value\")");
               test.printVarArgs("I am Param1 Value", "I am Param2 value");
               System.out.println("Calling varArgs with three parameter as test.printVarArgs(\"I am Param1 Value\", \"I am Param2 value\", \"I am Param3 value\")");
               test.printVarArgs("I am Param1 Value", "I am Param2 value","I am Param2 value");
         public void printVarArgs(String param1, String param2, Object...objects) {
              System.out.println("\nparam1 = "+param1+"\nparam2 = "+param2);
              System.out.println();
              System.out.println(" param3 [Object...objects] length = "+objects.length);
              System.out.println();
              if(objects.length > 0)
                   System.out.println("Param 3 is not empty and its first value is  = "+objects[0]);
              else
                   System.out.println("Param 3 is  empty and nothing to display, it is an empty array ");
    Output
    Calling varArgs with two parameter as test.printVarArgs("I am Param1 Value", "I am Param2 value")
    param1 = I am Param1 Value
    param2 = I am Param2 value
    param3 [Object...objects] length = 0
    Param 3 is empty and nothing to display, it is an empty array
    Calling varArgs with three parameter as test.printVarArgs("I am Param1 Value", "I am Param2 value", "I am Param3 value")
    param1 = I am Param1 Value
    param2 = I am Param2 value
    param3 [Object...objects] length = 1
    Param 3 is not empty and its first value is = I am Param2 value
    Edited by: Startup_Muthu on Mar 12, 2008 11:41 AM
    Edited by: Startup_Muthu on Mar 12, 2008 11:43 AM

  • How call a method from another class

    i make three class.class A,class B and class C.
    class A have One button.
    Class B have a action listener of that button.
    class c have a metod like
    public void test(){     }
    how can i call a method in class b from class c;
    is it necessary to pass the class a or b through the constructor of class c or another way to call the method.

    public class Foo
        public static void main(String[] args)
            Bar.staticFn();
            Bar b = new Bar();
            b.memberFn();
    class Bar
        public void memberFn()
            System.out.println("memberFn");
        public static void staticFn()
            System.out.println("staticFn");
      }

  • Calling native method

    Guys please help me with following error.
    I am running a simple JNI program,after creating and loading the dll i am getting following error.......
    Exception in thread "main" java.lang.UnsatisfiedLinkError: print
    "print" is the native method in java class Hello.java
    Hello.h has method declaration as :
    JNIEXPORT void JNICALL Java_Hello_print
    (JNIEnv *, jobject);
    and C++ file has method defined as :
    JNIEXPORT void JNICALL
    Java_Hello_print(JNIEnv *env, jobject obj)
    printf("Hello World!\n");
    return;
    please help me out...it has been 3 days banging against JNI ...

    Guys please help me with following error.
    I am running a simple JNI program,after creating and
    loading the dll i am getting following error.......
    Exception in thread "main"
    java.lang.UnsatisfiedLinkError: print
    "print" is the native method in java class
    Hello.java
    Hello.h has method declaration as :
    JNIEXPORT void JNICALL Java_Hello_print
    (JNIEnv *, jobject);
    and C++ file has method defined as :
    JNIEXPORT void JNICALL
    Java_Hello_print(JNIEnv *env, jobject obj)
    printf("Hello World!\n");
    return;
    please help me out...it has been 3 days banging
    against JNI ...If your Java code is in a package, then your native header file declaration is wrong. The javah tool expects the fully qualified class name. So, if your Hello class is in package com.foo.hello, you should generate the header file like this:
    javah com.foo.hello.HelloThen the native header declaration will look like this:
    JNIEXPORT void JNICALL Java_com_foo_hello_Hello_print
    (JNIEnv *, jobject);

  • Error calling native methods

    HI
    I declared a static native method in a class and using the System.loadLibrary() method i load the dll.
    Now if i want to call the method from another class using instance of that class where i declare the native method, it shows an error
    java.lang.SpecifiedPathLink error. I have put the dll outside the package in the same directory.
    can anyone help me regarding this problem

    it shows this exception
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no PerfMonitor in jav
    a.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1491)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:834)
    at C3.CPUMemoryUsage.<clinit>(CPUMemoryUsage.java:6)
    at C3.Node.main(Node.java:18)

  • Call a methode without opening the main view

    Hi,
    I have a function that calls a web dynpro application. The handledefault methode of the window from this web dynproapplication searches for a url of a picture and opens it with my browser.
    This works well.
    But there are two windows open: my picture and the empty web dynpro main view.
    How can I stop this? I just want the window with my picture.
    Thanks,
    Martina.

    Hi Manigandaan,
    I deleted  the empty main view from the webdynpro window.
    But the result is always the same:
    1 empty window and
    1 window with my url
    this is the code in the handledefault (after the data declaration):
    DATA lo_window_manager TYPE REF TO   if_wd_window_manager.
       DATA lo_api_component  TYPE REF TO   if_wd_component.
       DATA lo_window         TYPE REF TO   if_wd_window.
       DATA ld_url            TYPE          string.
       lo_api_component  = wd_comp_controller->wd_get_api( ).
       lo_window_manager = lo_api_component->get_window_manager( ).
    ld_url = lv_doclink.
      data lo_api_controller type ref to if_wd_view_controller.
      data lo_window_ctlr TYPE REF TO if_wd_window_controller.
      lo_api_controller = wd_this->wd_get_api( ).
      lo_window_ctlr = lo_api_controller->GET_EMBEDDING_WINDOW_CTLR( ).
    * get the control for window to be closed
      lo_window = lo_window_ctlr->get_window( ).
    * this will close the window
      lo_window->close( delete_window = abap_true ).
    if the ld_url is i.e. 'http://www.google.com' I get one browser window with google and another
    browser window which is empty. The URL of this empty browser window is the url with which
    i called the web dynpro application. But I don't need this window, how can I avoid this?
    Thank you very much!!!
    Martina

  • How call javascript method from parent window to iframe

    hi....
    i need to call javascript a method which located in iframe..
    in my java script file i used like this.
    window.frames[0].getHtml();
    it will working in IE but mozilla is not supporting
    pls help me..
    thanks
    Edited by: fsfsfsdfs on Nov 7, 2008 1:02 AM

    Sorry, Javascript is not Java and for sure not JSF.
    Repost the question at a forum devoted to Javascript.
    There are ones at [webdeveloper.com|http://www.webdeveloper.com] and [dynamicdrive.com|http://www.dynamicdrive.com].
    I can give you at most one hint: [DOM reference|https://developer.mozilla.org/en/DOM].
    Good luck.

  • Calling a method within an application?

    Hi I'm a student taking an intro Java class and right now I have to develop and application that prompts for someone to input a character of the alphabet and it will display the corresponding number on a telephone that it is listed under. The main method gets the input from the user and we are required to retrieve the corresponding digit to the character from a separate method using either a switch statement or a nested if-then-else statement to determine what the digit is. I'm having trouble calling that method in the main class which is another requirement. any suggestions?
    public class Hmwk08
         * Main driver begins program execution.
         * @param args program arguments
        public static void main(String[] args) throws Exception
            char letter;
            char ch;
            int relatesTo;
            PrintStream win = new PrintStream(System.out);
            Scanner in = new Scanner(System.in);
            String newLine = System.getProperty("line.separator");
            win.println("Given a letter of the alphabet, this program" + newLine
                        + "will tell you the corresponding digit on a" + newLine
                        + "telephone keypad.");
            win.println();
            win.print("Enter a letter: ");
            letter = in.nextLine().charAt(0);
            letter = Character.toUpperCase(letter);
         * Get the digit on a telephone keypad that corresponds
         * to the specified character. If the character is neither
         * a letter nor a digit, this method will retun the
         * asterisk character: '*'
         * @param letter the specified character
         * @return the corresponding digit
        private static char getPhoneDigit(char letter)
            char digit;
            digit = '*';
            if(letter == 'A' || letter == 'B' || letter == 'C')
                digit = '1';
            return digit;
    }

    Your method is static so you can call your method without creating a Hmwk08 object.
    char result = getPhoneDigit(letter);Would suffice in your main method
    Mel

  • Error call JNI method

    In call native method print in sign applet got following error:
    java.lang.UnsatisfiedLinkError: LabelPrinter.print Possible causes: If you are trying to use J/Direct (@dll.import), check your compiler version (for JVC, requires 4336 or greater.) If you are trying to use RNI, there are new requirements: see documentation.
    at LabelPrinter.print (LabelPrinter.java)
    at LabelPrinter.start (LabelPrinter.java:110)
    at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
    at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
    at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
    at com/ms/applet/AppletPanel.run (AppletPanel.java)
    at java/lang/Thread.run (Thread.java)
    I not using J/Direct or RNI.
    Any ideas?
    Thanks
    Carlo Cerqueira

    This could be a matter of incorrect case in the Method or library you are calling out to - or it could be that the DLL is not found - are you specifying the full path to it on the client system?

  • Errors in compiling native method

    I am trying to call a native method from a java source program. I generated header file by javah and wrote c file for native method implementation. I work on RedHat Linux-7.2.
    Java file for native method:-
    class HelloNative
    {  public static native void greeting();
    static
    {  System.loadLibrary("HelloNative");
    Java file for calling native method(main java file):-
    class HelloNativeTest
    {  public static void main(String[] args)
    {  HelloNative.greeting();
    C file implementing native method:-
    #include <stdio.h>
    JNIEXPORT void JNICALL Java_HelloNative_greeting
    (JNIEnv* env, jclass cl)
    {  printf("Hello world!\n");
         I am using following command for compiling c source file:-
    cc -G -I/usr/java/jdk1.3.1/include -I/usr/java/jdk1.3.1/include/linux HelloNative.c -o HelloNative.so
    It gave me followig errors on compiling:-
    cc: unrecognized option `-G'
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function `_start':
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status.

    Looks to me like you're not telling the linker to create a library (DLL). I'm not familiar with Linux, but clearly if the linker if looking for 'main' then its trying to build an executable.

Maybe you are looking for

  • Lag in iTunes Playback via ATV

    I recently noticed a serious lag in my iTunes playback over my ATV.  I can see the library and the playlists, but when I select music, I get the spinning wheel for various lengths of time until it finally loads.  Playback may or may not be consistent

  • How to set the language key in Sales document header text?

    Hi Guys, When I am creating a sales order I found in the header text tab only three languages English, Thai and Ukranian are mentained.. So can you please tell me how to add/ delete more language keys in language key field in a step by step process??

  • Sender File Adapter content conversion problem

    Hi all, is it possible to do content conversion like this: Key;Field1;Field2;Field3 PO00H;0482000000;20061102;PL61 PO01I;00010;0A720;Material 1;100.000 PO02D;20061102;100.000; PO00H;0482000001;20061102;PL63 PO01I;00010;0A730;Material 2;40.000 PO02D;2

  • IPad and iTunes Match

    Whenever I turn on iTunes Match on my ipad it warns me that all music currently on my ipad will be replaced by songs and lists from iTunes Match...in the process I lose a lot off music, not to mention time put in....why does it do this?

  • Match Certain word in a String

    Hi all, I'm actually doing a project regrading e-learning. And i'm suppose to create a set of questions for each topics using labview. So Is there any way that i can match certain word in the string to make sure that answer is correct? Cause i'm sure