This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI vs simply running an external program.  RSS feed

 
Dylan Margoczi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning Ladies and gents.

I was just wondering if it's better if possible to run an external ".exe" program (maybe written in c) rather than using JNI.

I've had a look at JNI and it looks like it could be alot easier to simply just run an exe.

I need this for getting the hard drive serial number (Which I know can't be done in java).

Any advice or thoughts on this topic would be greatly appreciated.

thanks in advance.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Running an external program is much slower than calling a JNI function. But, if you are only doing it once (probably true in your case), running an external program may be fast enough.

Passing complicated data between and external program and your Java code can be more difficult than doing it in JNI. However, in your case, the data is unlikely to be complicated.

Once you have added your first bit of JNI to your program, every subsequent bit of JNI is much easier than the first; you'll already have sorted out how to build the library, how to load it, how to deploy it in your installations etc. Therefore, think carefully. If getting the hard-drive serial number is the only thing you need to do outside pure Java, it's probably not worth JNI. If you are likely to end up needing lots of similar facilities, you should probably go for JNI.
 
Dylan Margoczi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the advice Peter.

I'll take the external program route as I highly doubt I'll need to do anything externally again.

thanks again.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!