• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Gradle and JNI

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am looking for article how to build a simple JNI application between Java and C++ (can be gradle but not a must)
something that gives example of step by step.

Thanks
 
Bartender
Posts: 20940
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JNI doesn't get seen much anymore. It's really only necessary when you need to talk to OS-specific functions and/or direct to hardware. These days, often those jobs can be handed off to some sort of specialized server using stock networking functions.

So JNI should be a last resort. The minute you add a JNI component to a Java app, it loses its write-once/run-anywhere abilities and gets tied to a specific environment.

Having said that, here's a project that uses JNI, I believe:

https://github.com/hypfvieh/dbus-java

This is a library that talks to the Linux dbus subsystem. The dbus replaced the older CORBA inter-application interface named ORBIT. You apparently can run dbus on OSX and BSD and there have been efforts to get it to work with Windows (although DCOM and other Windows-only constructs are the channels that Microsoft code uses).

At any rate, this project is Maven-driven, so it's a start. Should expect that, if anything, you could simplify it if you translated it to gradle.
 
Peter Benda
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for the kink
i understand about performance issues
but that are things tat i want the Java to interact with window componenets.
do you know maybe a project sample that interacts with something on windows
 
Tim Holloway
Bartender
Posts: 20940
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't written any software for Windows since 2007.

But what I'd normally do is put my Windows-specific code in a DLL and have the JNI call its API, unless the functions were really trivial.

A JNI class implements a Java class, just with internal code in C instead of in bytecodes. You can probably get a pretty good start on a Windows JNI class just by taking the dbus JNI source code as a starting point. Sun didn't waste a whole lot of time writing stuff that only runs on Windows. In fact, at the time the original functionality was designed, they were developing on Solaris. So the overall organization of JNI code can be expected to be very similar regardless of the OS it's compiled for. Only the code that the JNI module itself calls would be OS-specific.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!