This discussion is archived
1 Reply Latest reply: Apr 10, 2012 2:35 PM by jschellSomeoneStoleMyAlias RSS

JNI with Mac OSX Library

928928 Newbie
Currently Being Moderated
Hi guys,

I am looking for some guidance with regards to JNI on MAC.

Basically I have a scanner driver library (libopn_driver.dylib) and I have a .h file for this library written in C.
If I want to use it with Java, would I need to write my own .h file that Java can understand?

How should I go around this?

Note: I am currently using JNA but part of the code is not working and I think there is an issue with pointers.

Any ideas would be appreciated.

Thanks
  • 1. Re: JNI with Mac OSX Library
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    user9337129 wrote:
    Hi guys,

    I am looking for some guidance with regards to JNI on MAC.

    Basically I have a scanner driver library (libopn_driver.dylib) and I have a .h file for this library written in C.
    If I want to use it with Java, would I need to write my own .h file that Java can understand?

    How should I go around this?
    To use JNI.
    1. Determine what you want to do in java and your application.
    2. Design an interface (generic term) the defines 1. This is NOT language specific. Rather it is a specification that allows one to implement something in a language.
    3. Write C code that wraps the library which implements what is defined in 2.
    4. Test 3
    5. Write java/jni code that interacts with 3.
    6. Test 5.
    Any ideas would be appreciated.
    Don't use JNI - including via JNA.

    Instead...
    1. Determine what you want to do in java and your application.
    2. Design an interface (generic term) the defines 1. This is NOT language specific. Rather it is a specification that allows one to implement something in a language.
    3. Write C code that wraps the library which implements what is defined in 2.
    4. Test 3
    5. Add a communications interface in C. This can be implemented using files, stdio or sockets.
    6. Test 5.
    7. Wrap all of the above in an executable.

    1. Write java code that runs the above app via Runtime.exec() or ProcessBuilder.
    2. Write java code that uses the communications interface from 5.
    3. Test the above.

    Advantages to this.
    - C code errors cannot cause the VM to exit.
    - Much easier to test and debug the C code.
    - One need not figure out JNI at all.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points