tags:

views:

1261

answers:

6

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 huge) string and returns another (also possible 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 rather just find some free, pure Java solution...

A: 

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.

Eddie
+2  A: 

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.

Thelious
A: 

Thanks a lot for your responses...

They've been quite helpful

The com+ component is rather trivial, it just takes a xml message, parses a few tags, open an SQL DB, an execute the appropiate stored procedure, passing alogn qhe xml

then it gets a resultset, an serializes it to a xml...

so I think the best way to go is to code the whole thing in java and forget about com+

once again, thanks a lot...

saludos

sas

opensas
+2  A: 

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

Brian Agnew
A: 

Hi,

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

Matt
+1  A: 

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/