opensas
opensas

Reputation: 63545

How to execute COM+ libraries from Java using a free method

I have a COM+ component developed with VB6.

After registering it with the component services manager COM+ application, I can use it from ASP like this

Set Comando = Server.CreateObject("JuiciosComando.clsComando")
ComandoExecute = Comando.execute(Xml)
Set Comando = Nothing

That's all I need, the component just receives a (maybe a huge) string and returns another (also possibly huge) string...

Is there some way to access this very same component from Java?

What I've found so far is J-Integra but it's a commercial product.

I've also found this thread on codeguru.com but my C++.NET knowledge is rather poor, besides I would rather just find a free, pure Java solution.

Upvotes: 0

Views: 4691

Answers (5)

Gerrit Grunwald
Gerrit Grunwald

Reputation:

Maybe you should try com4j which works great for me and supports also com events. You can find it here: https://com4j.dev.java.net/

Upvotes: 1

Matt
Matt

Reputation: 546

Sorry, I know this thread is old, but j-Interop could help you out.

From the j-interop.org website:

"j-Interop is a Java Open Source library (under LGPL) that implements the DCOM wire protocol (MSRPC) to enable development of Pure, Bi-Directional, Non-Native Java applications which can interoperate with any COM component."

Cheers, Matt

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272347

I can confirm that JACOB works pretty well. I've used it for numerous COM automation projects without any issues. And it's free...

Upvotes: 4

Thelious
Thelious

Reputation: 86

As Eddie mentioned, you have two main methods of using COM via java: using C++ and writing a JNI wrapper or using a third party JAR to wrap the COM object.

I've attempted to use C++ to wrap a COM object in the past - it's not for the faint hearted - it is not easy to do and its very easy to leak resources.

I've also used two third party JAR's: ComfyJ and JACOB.

ComfyJ was really easy to use and also included a codegen utility to generate java wrapper classes for your COM classes.

It can be downloaded and trialed via http://www.teamdev.com/comfyj/index.jsf

(I am not affiliated with TeamDev in any way!)

If you are desperate for a totally free solution, you could also try JACOB (http://sourceforge.net/projects/jacob-project/).

I had issues with documentation, but it was relatively stable.

Upvotes: 5

Eddie
Eddie

Reputation: 54421

I've worked with an application that originally tried JNI to interact with native code to access COM, and it ended up being very very difficult to maintain and debug. (Fortunately, I wasn't the person working on that part of the application!) As a result of this experience, I now recommend that Java code needing to access COM do it by writing a C# application to do COM access, and use a nailed-up socket between the two applications.

JNI is unnecessarily risky and difficult in Java, as compared to the equivalent in C#, so the most stable way to do this from Java is to not do it from Java. Delegate the COM access to something that has expertise in COM access: C#.

Your other alternative is to license some 3rd party library that itself manages the JNI for you. But unless you enjoy pain, I highly recommend against rolling your own JNI solution.

Added later: As you see in the link you referenced, JNI code can crash the entire JVM. At least if the COM access is at the other end of a socket, if the C# application crashes, you only lose your socket which you can easily reestablish when the C# application returns. However, C# is far less likely to crash when accessing COM. Yes, it's nicer to have a pure 100% Java solution, but sometimes it's really a lot better to delegate tasks to another language.

Upvotes: 2

Related Questions