Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing Java Native Methods in WIndows and AIX environment

Posted on 2014-02-05
8
Medium Priority
?
270 Views
Last Modified: 2014-02-13
I have logic written in Native Codes (C++) and I need to generate some file by which I can access those class methods in Java. The generated native file needs to run on windows and AIX environments.

What are the steps to do that?
0
Comment
Question by:jgdvishnu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 39836776
Why don't you Google JNI and JNA, and read up about it 'at source'?
0
 
LVL 86

Expert Comment

by:jkr
ID: 39836878
... a little bit more precise: http://www.codeproject.com/Articles/2876/JNI-Basics-1

This article and the follow-ups will introduce you on how to call native C/C++ code from Java via JNI. The prerequisites are that your C/C++ code are compiled into a DLL or shared library (for AIX), but that's pretty much it.

A little less brief is this document by IBM: http://www.carfield.com.hk/document/java/tutorial/jni_tutorial.pdf - quite an in-depth introduction into using JNI, will take quite more time to read that one compared to the other article.
0
 
LVL 28

Expert Comment

by:dpearson
ID: 39837940
JNI is certainly the right technology but it's very complex to build it by hand unless you have a very simple set of methods to support.  The complexity starts to come in when you wish to pass data back and forth between Java and C++, especially as they don't use the same memory allocation system.

For anything mildly complicated I'd suggest taking a good look at SWIG (http://www.swig.org/).  It's a toolkit designed to support interfacing C++ code to other languages - and Java is one of the supported ones.

If you look through the tutorials you can see how to use SWIG to generate the JNI code that you need.  Also using a tool like this has a huge advantage if you ever modify the C++ code that you are calling to because you can just press a button and regenerate the Java interface.

Hope that helps,

Doug
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jgdvishnu
ID: 39849066
Swig is the good tool but it has no user interface (Only command line).

I checked eclipse CPP but the problem is it does not have the libraries of C++ to run. To make this compile and run I installed MINGW(mingw-get-setup) but still the code did not recognise the compile.
MingW still fails to resolve the issue

Or Is there a free tool that has user interface and easy to make shared libraries/dll/exe)
0
 
LVL 28

Expert Comment

by:dpearson
ID: 39849305
I'm only familiar with SWIG, which as you say has no GUI.  It's command line only.

Doug
0
 

Author Comment

by:jgdvishnu
ID: 39849823
Doug,

Is there a short step by step tutorial using swig to compile and run c++ code. I feel little rushed
0
 
LVL 28

Accepted Solution

by:
dpearson earned 2000 total points
ID: 39850667
Have a go at:
http://swig.org/tutorial.html

It shows you how to get things running for a simple piece of C++ code that shouldn't take you more than a few minutes to try out.  (You can skip all of the other languages and just focus on the C++ and Java parts).

Doug
0
 

Author Comment

by:jgdvishnu
ID: 39857017
thanks Doug,

I installed swig on windows however what additional software I need to run gcc commands.
libgmp-10.jpg
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question