I have a source code library from Renesas for their Co2 sensor. The source code library is completely written in C language and a static library (with .a extension) of it is given for the Co2 sensor which was helpful for me to use it in any microcontroller that uses C/C++ language. Even there are a lot of examples of it.
So, I have a microcontroller called DPM5050 which runs in Java programming language. Therefore, I came to know, that it is possible to use the native code in JAVA using JNI (Java Native Interface). I also came to know that to use native source code in Java, I need a dynamic link library. But I only have a static library which is provided by the Renesas.
My question is how can I do that using a static library that was given by Renesas?
Can I able to change the static library to the dynamic link library by myself without contacting Renesas?
And how to implement this in Java using JNI to use the native source code library provided by the Renesas?
Since I just came to know about this JNI technology to use native
source code in Java. So, I would also like to ask you to give me
suggestions or opinions on this topic. And I am also looking for some
good documentation with examples or tutorials or guidance to proceed
further.
Right now, I am reading Java APIs, Extensions and Libraries: With JavaFX, JDBC, jmod, jlink, Networking, and the Process API - by Kishori Sharan's book in Chapter 7 of this book they have some details about JNI.
I am looking forward to your responses. Thanks in advance.
Kind Regards,
Mustaq.
Related
We have Objective C and Andoid Java applications and would like to create a component using C# and Xamarin that would interact.
Is there a way these technologies can communicate with each other (Objective C <-> Xamarin and Android Java <-> Xamarin).
Not sure how you do this but searching here it may be possible to create a static library in Objective C/Java that can be called from Xamarin.
From there I understand that you can start the Objective C/Java app from the Xamarin Main method and afterwards can call other static library methods.
Ideally we would like to call from the Objective C/Java app to Xamarin.
According to Miguel in this post it is possible but are there any examples anywhere.
Hope the explanation makes sense.
Thanks
From the wording of your question, this is not possible.
Xamarin does offer the ability to create 'bindings' between C# and Objective C/Java static libraries and has a section on the Developer documentation on doing so (Objective C Bindings or Java Wrappers).
The key part is that this is for static libraries and not for general application functionality i.e. user interactions.
You will need to weigh up the benefit between migrating the disparate projects to a shared Xamarin solution whereby you will enjoy the code sharing (especially with the Xamarin Forms offering) or simply writing the functionality into separate libraries for the different platforms.
Good luck
I wrote a Java application for my company which works great. Now I am asked to interface my application with an API of a piece of hardware.
The API is implemented in a Windows dynamic link library (DLL). The samples that come with the API were written in Visual C++ 6.0
and Visual Basic 5.0 (seems very old).
There is no Java API available. I am wondering if there is a way to use the DLLs with my Java application I wrote? Should I rewrite the application
in VB.NET or... (Would these APIs even work with VB.NET)?
This is the piece of hardware whose API I need to use:
http://www.sealevel.com/store/8004e-pci-express-16-reed-relay-output-16-isolated-input-digital-interface-3-13v.html
Any suggestions or ideas are appreciated.
Thank you
The API should work with VB .NET.
If the API is Open-Source you could try to add JNI support, so that you can use it in Java.
Otherwise you could try to write the Application in C++. The difference to Java is not that big.
1) Use JNI, try using some java-c++ bridge which will make your life easy - see this https://code.google.com/p/javacpp/
2) Yes you can call native api's in vb.net
My company uses .NET for all development, and we integrate with an ERP made in .NET.
The ERP API is a collection of interops that we simply reference from our .NET project and we are ready to do whatever we want with it.
Recently we are thinking in JAVA development, but we have one concern, the integration with the .NET products we sell.
I've googled a bit and found JNA and JNI.
My questions are:
What is the best solution to "use" a .NET dll in JAVA?
Do they have limitations in functionality or performance?
Thank you.
I prefer JNA over JNI. JNI is more error prone. Boilerplate code you need to write makes it ugly. Also JNI is more C-ish than JNA. I haven't used JNI lately but JNA is hosted at Github, making it more reliable for me. I'm not sure whether JNI will be supported in future. You can see JNA#Github here.
In both you need to be get used to type mappings.
Are there inexpensive or free gateways from .NET to Java? I'm looking at some data acquisition hardware which has drivers for C/C++ and .NET -- I really don't want to do any programming in .NET.
Update: I haven't done what I originally wanted to do, but I've done something similar, using JNA to encapsulate some functions from a DLL, in order to control a USB hardware device from Java. (the DLL comes from the device manufacturer) It works really nicely. Thanks!
You could also try to use JNA for accessing the native library. JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java codeāno JNI or native code is required. If their API is fairly straight foward, this might be the path of least resistance.
See their getting started guide where they call some native code (printf and GetSystemTime).
Well, there's JNBridge and EZ JCom, just from a Google search.
You could also use IKVM which is a slightly different approach.
(Any reason for not wanting to learn .NET, out of interest? It's a nice platform, and C# is a lovely language...)
If they have C++ versions of the drivers then you could write a wrapper around it using JNI and then load that in Java. JNI can be a bit of a pain, but it would let you use the C++ version of their drivers and not have to deal with .Net at all if you don't want.
I am partial to the recommendation to jump in the deep end with C# since it is so similar to Java. I did this and used IKVM to compile my favorite Java libs. to .NET assemblies and you get [nearly] all the core java runtime classes to boot, so if you tire of trying to find just the right C# collection type, you can always go back to java.util. (No generic collections though. Not sure why.)
Depending on what platform you're on, you have several choices for free IDEs too. For windows you can get Visual Studio Express for free but I also use SharpDevelop. You can also get the Mono IDE on Linux (and a few flavours of Unix, I think ?).
The C# learning curve is shallow if you already know Java. I only blew off 1.5 limbs on landmines that came out of nowhere for reasons I still don't understand, but workarounds were easy to come by. The worst thing about it was the darn developer docs which are AWFUL on account of being so slow. I really miss the snappiness of JavaDoc. Not only are the online docs incredibly slow, the problem is compounded by someones's iffy decision to put class summaries, constructors and methods/properties all on seperate pages so it just takes forever. Someone said to get the docs installer and install docs locally for a slightly improved experience. Not a bad idea I suppose.
I am author of jni4net, open source interprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
If you have a Java application, the JNI mentioned by the others will be the way to go. You write some wrapper classes, and that's it.
If writing the wrappes is a too big task (depending on the number of methods you have to wrap), have a look at SWIG . I think it generates wrappers automatically, but I never actually used it.
If you want to code in the Java language, but you don't care if your program will run on the JRE/JVM, then you might as well use Microsoft J#. Basically, it's writing Java-Code wich is compiled to .NET-Bytecode and can use the .NET classes of the driver as well as your existing Java classes. With J# you will run into problems if your existing Java-code is newer than Java 1.4, look at this question on how to solve them.
From that point on, you could later add code in J#, C# or any other .NET language. However, you won't get back to the JRE/JVM easily.
I'm wondering if a Java library can be called from a VB.net application.
(A Google search turns up lots of shady answers, but nothing definitive)
No, you can't. Unless you are willing to use some "J#" libraries (which is not nearly the same as Java) or IKVM which is a Java implementation that runs on top of .NET, but as their documentation says:
IKVM.OpenJDK.ClassLibrary.dll: compiled version of the Java class libraries derived from the OpenJDK class library with some parts filled in with code from GNU Classpath and IcedTea, plus some additional IKVM.NET specific code.
So it's not the real deal.
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
You can call Java from .NET if you wrap it in some form to make it accessable and the easiest way is typically to use a Runtime bridge like
http://www.jnbridge.com/
Other way is to wrap your API with java webservices.
check this also http://www.devx.com/interop/Article/19945
Nothing out of the box.
Most java/.net interop that I know uses web services.
If you can create COM components with Java, you can use tlbimp to create an interop assembly for using in VB.Net.
If can create standard DLLs that can be used from C++ with Java, you can write P/Invoke declarations and call them from VB.Net.
If you can create a web service with Java, you can generate proxy class from the WSDL and call it from VB.Net.
In any case, chances are the Java component will live in a separate process. I doubt you can load both the Java VM and the CLR in the same process.
If you have the source code and compile it using the J# compiler, then the answer is yes. If you want to call any pre-Java 2 (aka 1.2) libraries, then these are included pretty much verbatim with J#. More recent stuff is going to be tricky though (i.e., it's not there).
An example where this is used commercially are the yFiles graph layout algorithms from yWorks. These were originally just a Java library, but for the past few years they've been offering a .NET version, which is just the Java version compiled with Visual J#.
It's not without problems, and there are some limitations that you can't get around, but it can be done. So... unfortunately this answer looks pretty shady as well.
You could use JNI to instantiate a virtual machine and then use Java Classes. It will be some fun, though, because you would need to use C++ as a bridge between VB.Net and Java.
This article in java world has a quick tutorial on how to use Java from C++ and viceversa.
http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
If you have the source, Visual Studio will let you convert Java code into c#.