EmbeddedRelated.com
Forums

Integrating Java application on embedded product running C code

Started by ssubbarayan March 4, 2008
Dear Gurus,
We have a requirement in our embedded consumer product to integrate
Java application.The product has got some C code already running.
(Theres a command based application used for testing purpose in C
language).For providing a demo,we need to integrate Java with this
existing application.
We dont want to reinvent both(Both application and Test tool) in same
language as its quite time consuming.Can someone point me in right
direction on how this can be done?

Following are ideas coming to my mind:
1)I searched net and it gives me a tutorial stating about JNI(Java
Native interface) which is needed to interface java to other languages
like C,C++.
2)From JNI tutorial,it seems we need DLL support to do this,but the
tutorial is for PC and not embedded product.I am not sure whether we
need DLL support.

The link containing tutorials is below:
http://www.math.ucla.edu/~anderson/JAVAclass/JavaInterface/JavaInterface.html

As I am new to Java,it would be helpful if some of you who have done
similar work let me know what all is needed environment wise as well
as todo programming stuff.
Adding to this the whole integrated application will run on Linux
based paltform on my embedded product.

Looking farward for all your replies and advanced thanks for the same,
Regards,
s.subbarayan


ssubbarayan <ssubba@gmail.com> wrote:

> We have a requirement in our embedded consumer product to integrate > Java application.The product has got some C code already running. > (Theres a command based application used for testing purpose in C > language).For providing a demo,we need to integrate Java with this > existing application. > We dont want to reinvent both(Both application and Test tool) in same > language as its quite time consuming.Can someone point me in right > direction on how this can be done?
So you want to call C code from the JVM as far as I understod? Let's say you have class X: public class X { public int method() { return functionInC(); } private native int functionInC(); } 1. compile X.java 2. run "javah -classpath ./ X" 3. now you have "X.h" which you then implement and call your other C modules from there Actually, the following article is quite good about JNI: http://www.acm.org/crossroads/xrds4-2/jni.html
> 2)From JNI tutorial,it seems we need DLL support to do this,but the > tutorial is for PC and not embedded product.I am not sure whether we > need DLL support.
Yep. The easiest way is probably to patch the JVM so that System.loadLibrary() does something else than loads a DLL/.so. On the HP NonStop platform it used to be so, that one statically linked the native code to the JVM.. What JVM you are using? -- Jyrki Saarinen http://koti.welho.com/jsaari88/
ssubbarayan <ssubba@gmail.com> wrote:

> We have a requirement in our embedded consumer product to integrate > Java application.The product has got some C code already running. > (Theres a command based application used for testing purpose in C > language).For providing a demo,we need to integrate Java with this > existing application. > We dont want to reinvent both(Both application and Test tool) in same > language as its quite time consuming.Can someone point me in right > direction on how this can be done?
So you want to call C code from the JVM as far as I understod? Let's say you have class X: public class X { public int method() { return functionInC(); } private native int functionInC(); } 1. compile X.java 2. run "javah -classpath ./ X" 3. now you have "X.h" which you then implement and call your other C modules from there Actually, the following article is quite good about JNI: http://www.acm.org/crossroads/xrds4-2/jni.html
> 2)From JNI tutorial,it seems we need DLL support to do this,but the > tutorial is for PC and not embedded product.I am not sure whether we > need DLL support.
Yep. The easiest way is probably to patch the JVM so that System.loadLibrary() does something else than loads a DLL/.so. On the HP NonStop platform it used to be so, that one statically linked the native code to the JVM.. What JVM you are going to use? -- Jyrki Saarinen http://koti.welho.com/jsaari88/
On Mon, 3 Mar 2008 23:04:49 -0800 (PST), ssubbarayan
<ssubba@gmail.com> wrote in comp.arch.embedded:

> Dear Gurus, > We have a requirement in our embedded consumer product to integrate > Java application.The product has got some C code already running. > (Theres a command based application used for testing purpose in C > language).For providing a demo,we need to integrate Java with this > existing application. > We dont want to reinvent both(Both application and Test tool) in same > language as its quite time consuming.Can someone point me in right > direction on how this can be done? > > Following are ideas coming to my mind: > 1)I searched net and it gives me a tutorial stating about JNI(Java > Native interface) which is needed to interface java to other languages > like C,C++. > 2)From JNI tutorial,it seems we need DLL support to do this,but the > tutorial is for PC and not embedded product.I am not sure whether we > need DLL support.
The first thing you need to run any Java applications at all is a JVM, a Java Virtual Machine. There are JVM's for all common desktop systems, but all of them are very platform specific. What operating system are you running on your embedded system? Is there even a JVM available for your operating system? If you are running an OS that has a JVM, you should find out how to use JNI for that OS. You mention DLL, which is a Windows concept. Are you running Windows on your embedded system? -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
On Mar 5, 7:45=A0am, Jack Klein <jackkl...@spamcop.net> wrote:
> On Mon, 3 Mar 2008 23:04:49 -0800 (PST), ssubbarayan > <ssu...@gmail.com> wrote in comp.arch.embedded: > > > > > > > Dear Gurus, > > We have a requirement in our embedded consumer product to integrate > > Java application.The product has got some C code already running. > > (Theres a command based application used for testing purpose in C > > language).For providing a demo,we need to integrate Java with this > > existing application. > > We dont want to reinvent both(Both application and Test tool) in same > > language as its quite time consuming.Can someone point me in right > > direction on how this can be done? > > > Following are ideas coming to my mind: > > 1)I searched net and it gives me a tutorial stating about JNI(Java > > Native interface) which is needed to interface java to other languages > > like C,C++. > > 2)From JNI tutorial,it seems we need DLL support to do this,but the > > tutorial is for PC and not embedded product.I am not sure whether we > > need DLL support. > > The first thing you need to run any Java applications at all is a JVM, > a Java Virtual Machine. =A0There are JVM's for all common desktop > systems, but all of them are very platform specific. > > What operating system are you running on your embedded system? =A0Is > there even a JVM available for your operating system? =A0If you are > running an OS that has a JVM, you should find out how to use JNI for > that OS. > > You mention DLL, which is a Windows concept. =A0Are you running Windows > on your embedded system? > > -- > Jack Klein > Home:http://JK-Technology.Com > FAQs for > comp.lang.chttp://c-faq.com/ > comp.lang.c++http://www.parashift.com/c++-faq-lite/ > alt.comp.lang.learn.c-c++http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.ht=
ml- Hide quoted text -
> > - Show quoted text -
Hi, Thanks for all your replies. Our Target board is going to run on Linux OS customised by our Hardware vendor.Host development system is CentOS(Linux flavour). I was given the requirement to have Java Run Time environment version 1.5.I believe I need to look for JVM for my Linux on board.The linux on board is based on version 2.2 kernel of linux. Regarding DLL,I read it in a link(I posted) .The link mentions about using DLL for windows PC.I would like to know whether there should be something similar to DLL in my target board based on Linux too? I am new to lot of technologies used in this project viz.,Java,Linux,Target Hardware etc. Can some one also let me let me what else is needed environment wise/ programming wise more other then JVM mentioned by you? Any steps to be followed before jumping into programming will be of great help to me. Looking farward for your replies, Thanks and Regards, S.Subbarayan
ssubbarayan <ssubba@gmail.com> wrote:

> Regarding DLL,I read it in a link(I posted) .The link mentions about > using DLL for windows PC.I would like to know whether there should be > something similar to DLL in my target board based on Linux too?
Yes, *nix-systems usually have the concept of shared libraries. In the MS world they are often called DLLs, while in the *nix world they are called ".so". So, if your dynamically linked library is called BLA, on windows System.loadLibrary("BLA"); will load BLA.dll. On Linux for example the same call will load libBLA.so. Since you have a Linux based system, just compile your C code into a .so (gcc.gnu.org has instructions how to build a shared library), but it into /usr/lib or whaterver place is approriate and use System.loadLibrary(). -- Jyrki Saarinen http://koti.welho.com/jsaari88/