Any method for accessing Windows COM methods using Java? - java

I have an application which makes use of JNA to call functions from a hardware abstraction library in C++. One of the supported hardware devices requires Windows COM subsystem to be initialized (via CoInitialize or CoInitializeEx).
Does anybody know any Java library which can do the trick? I know I could wrap some Windows functions, but if I had something ready and tested, that would be better. I found one called JACOB but it is said that the documentation is not good and it's been a long time since they last updated it.
Thanks!

We use Com4J (for external processes like Excel) and the SWT COM API (for embedded GUI components). Sometimes, we use Jacob, it depends on the control you want to control. Sometimes they don't implement the IDispatch interface correctly, and then only one of the Java Com APIs works.
We also had COM components that needed a VB6 wrapper DLL, which in turn can be called with Com4J, so prepare for some headaches!

Have a look # JCom (Java-COM Bridge)
Other implementation exist but I used this one and it worked for me..

Related

android use pcap library

I have a general question according an android app, I need to use some pcap functionality in my android app. Because java does not give the possibility in raw packet injections and low layer programming (as far as I know, pls correct me if I'm wrong) so I was looking for an alternative. So far I found the following:
ANDROID NDK
JNETPCAP
Any suggestions which one I should use or does anyone have other suggestions?
The JNI Solution
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.
The documentation on JNI is pretty complete on internet, a lot of tutorials exists on this subject such as this one.
If you want to easily wrap native code in JNI you can use Swig which allow you to automatically generate JNI code based on your C/C++ native headers.
The obtained JNI code should be compiled using the Android NDK as a dynamic library (.so). This library is to be placed in your application package under libs/. You can then invoke System.loadLibrary(path_to_you_dynamic_library) to load all the symbols contained in the library and use them in Java.
Using a third-party library
If you're afraid of getting headaches while figuring out how to use JNI, you can look at this library which does the hard work for you, and provides an API to manipulate raw sockets in Java.
http://www.savarese.com/software/rocksaw/
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.
Or you need to get a library that's already done that, such as, err, umm, jNetPcap.
One problem you may have with any attempt to do packet capture on Android - or any other OS using the Linux kernel - is that, by default, the underlying kernel mechanism used by libpcap (PF_PACKET sockets) requires root privileges. If there's a way to run your code as root, or to give it CAP_NET_RAW and possibly CAP_NET_ADMIN privileges, it might be possible to make it work.

Java RMI with Scala, is this possible?

Java RMI -Remote Method Invocation- is Java to Java only.
On the Scala website I read that the integration with Java is seamless and that:
Scala programs run on the Java VM, are byte code compatible with Java so you can make full use of existing Java libraries or existing application code. You can call Scala from Java and you can call Java from Scala, the integration is seamless.
Does this mean that I can successfully use a Java to Scala RMI?
Did anyone experiment this first-hand?
EDIT:
Any known or discovered gotchas??
Yes, here's a link to a message thread where it looks like somebody's done it. It says:
Yes it can! Thanks for help. I now have a little RMI-based pair of Scala programs that will be performing transfers of documents from one Documentum system to another (of a previous version); the Scala code is interacting very nicely with the Documentum Java libraries.
Figuring out how to get the method signatures to include throws RemoteException seems to have been the biggest hurdle.
Yes, this can be done. The rmi compiler works with java byte code, so the language used really doesn't matter. I've done this for a class project.
It would depend on what RMI library you are using but in general, the answer is "Yes." Although, note that if you write a method that returns (for example) a Scala collection like scala.collections.immutable.List, then your calling Java code will probably not be able to convert that to a java.util.List.

How to use winapi functions in java?

I am doing a project in java which has the function to add files in database, and i want to use winapi functions to select files.
How would i do that?
By far the easiest way is by using Java JNA, it already has translation from stcalls in.
You can find a basic tutorial for it (with Winapi example no less) on JavaWorld.
You could also use JNI, but JNI requires you to use specially built header files for interfacing and it's all in all harder to maintain and use. It's slightly faster in some cases though.
You want Java Native Interface - this tutorial shows you how to implement your own but you could easily just point to WinAPI functions - http://java.sun.com/docs/books/jni/download/jni.pdf
Here's an example I found with a quick Google - not the neatest webpage but still demonstrates the concept well http://edn.embarcadero.com/article/20679
I strongly advise JACOB (Java COM Bridge) for using COM interfaces.
http://sourceforge.net/projects/jacob-project/
I wrote an app for getting song infos from Amazon Web Services. Its a nice library to have.

Calling Java library from Objective C on Mac

I want to create native Mac OS X application using Cocoa + Objective C but I need to connect to proprietary data source, and for this, owner of the data source only provides Java library. So I need to somehow import this Java library into my project and call functions on its Java classes.(Or create java wrapper around this library and then call my wrapper from objective-C).
Now, how can I do this? Quick google search leads me to JNI but I haven't found any good and actual(current) article/tutorial. I would really need some HOW TO article, how to load this java library, start VM if needed, and how to create java objects and call functions on them. Really something simple and I can move from there. Thanks.
Just to clarify, I repeat: I WANT to call Java functions from Objective-C, I do NOT want to call native functions from Java.
You're probably looking for the Invocation API, a little-known corner of Java Native Interface (JNI) which allows you to load the Java runtime in-process.
That said, you might have an easier time of it with a Java service application that communicates with your Objective-C application over network sockets.
You're looking for the Java-Objective C bridge, try looking at this article or on Apple's developer site. Be aware it is deprecated, that is it isn't being kept up to date with changes to Cocoa. But if you're just using it for an API passing standard Java datatypes you should be OK.

What tools are available for creating in process COM servers in Java?

What tools are available for creating in process COM servers in Java?
J-Integra is the most comprehensive, complete solution you will probably find for using COM and Java together. The software has been used by many commercial products, big and small, to integrate COM and Java (both directions).
jacob-*-x86.dll and accompanied jacob.jar
Used it successfully to connect to TestDirector (which uses DCOM). Little bit tricky with memory management, but even .NET guys calling COM have troubles doing it.
link text
Any software used to access COM from Java (or another platform) is known as a "COM bridge".
The j-Interop project on sourceforge may be worth checking out.
Another alternative is JNI Wrapper/ComfyJ - it allows you to either generate Java proxy classes or use IDispatch. You can also trap and broadcast events (IConnectionPoint) and implement COM servers.

Categories