Menu

#39 Java/JNI: Generate method that registers methods with a VM

None
closed
None
5
2023-06-21
2006-07-14
Dennis
No

Goal:
----------------------
- Make SWIG usefull for programs that can not
be compiled as a DLL/.so
- Avoid use of System.loadLibrary in Java Code

Idea:
----------------------
- Modify Source/Modules/java.cxx
- Generate an extra method that calls the JNI function
RegisterNatives() to register the native methods
associated with a class
- This method should get a pointer to an instantiated VM,
e.g. some_name(JavaVM *jvm);

I would be gratefull if the Java maintainer could
either implement this functionality or provide me with
some information on how to integrate that into SWIG
since I am not familiar with the SWIG code at all.

Thank you, Dennis

Discussion

  • William Fulton

    William Fulton - 2006-09-01
    • assigned_to: nobody --> wsfulton
     
  • William Fulton

    William Fulton - 2006-09-01

    Logged In: YES
    user_id=242951

    If you could send me a working example of what you require
    (what the generated code would do), I'll take a look at how
    this could be implemented.

     
  • Mark Donszelmann

    Logged In: YES
    user_id=800216

    We actually modified SWIG 1.3.29 to do this.

    Goal
    -------------
    - Use a library which we only have in Java, from C++.

    Implementation
    ---------------
    - Mods to insert code to start JavaVM.
    - Mods to java.cxx to handle call to registration of methods.
    - Generation of calls for all classes to register their methods.

    It is all a bit crude still, but does seem to work.
    If there is a general interest by the SWIG team (Java) for
    this, I would be happy to send in my changes.

    Regards
    Mark Donszelmann

     
    • Andriy Gerasika

      Andriy Gerasika - 2023-06-21

      I am interested in this feature -- can you please send the changes, so I can integrate these into most recent version of Swig on Github?
      Thank You

       
  • Andras Varga

    Andras Varga - 2006-12-29

    Logged In: YES
    user_id=933227
    Originator: NO

    I have written a Perl script to generate the registerNatives() code from the xxxJNI.java file, but I'd really prefer if such functionality would be built into SWIG itself.

    In any case I'm willing to share the Perl script if there's interest.

    Andras

     
  • Olly Betts

    Olly Betts - 2021-10-07
    • status: open --> closed
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2021-10-07

    Closing as a duplicate, since this is also in the github tracker:

    https://github.com/swig/swig/issues/2034

     

Log in to post a comment.