I would like to know if it is possible to invoke a C# program using the .NET libraries from a Java application via JNI?
We have an exisiting Java application deployed over the web to client desktops (we bundle the jre along with the application). We have issues with the Java printing as it crashes the application when printing to certain printers. I would like to know if it would be possile to write a C# application that would be able to print - invoked from JNI. Would we have to bundle the .NET CLR along with the application to implement this?? As I do not have much exp with the .NET framework any help/suggestions would be highly appreciated.
I would like to know the answer too.
In my case, I would like to use MSMQ from Java without using any commerical bridge.
I know there is C/C++ MSMQ API, but if JNI can use the .NET classes, the coding would be much much simpler to call the MSMQ .NET classes than calling the C/C++ MSMQ API.
Re: Invoking C# program using .Net framework from a Java application
Feb 16, 2005 2:08 PM
(reply 5
of 10) (In reply to
#1 )
I found the C# code much easier to use along with the .NET libraries - do not have much exposure to Win 32 api - programming :-( Anyways thanks for all your responses - I think I have found a work around to my problem by using SWT/JFace.
...I would like to know if it
would be possile to write a C# application that would
be able to print - invoked from JNI. Would we have
to bundle the .NET CLR along with the application to
implement this?? As I do not have much exp with the
.NET framework any help/suggestions would be highly
appreciated.
Sure, you can do this. Writing the JNI code to bridge between Java and .NET can be pretty ugly, but there are third-party bridges like JNBridge (www.jnbridge.com) that encapsulate this and take care of it in a clean manner. Check it out and see if it does what you want.
I would like to know if it is possible to invoke a C#
program using the .NET libraries from a Java
application via JNI?
We have an exisiting Java application deployed over
the web to client desktops (we bundle the jre along
with the application). We have issues with the Java
printing as it crashes the application when printing
to certain printers. I would like to know if it
would be possile to write a C# application that would
be able to print - invoked from JNI. Would we have
to bundle the .NET CLR along with the application to
implement this?? As I do not have much exp with the
.NET framework any help/suggestions would be highly
appreciated.
thanks
Hi,
You should take a look at the J-Integra Interoperability suite.
http://j-integra.intrinsyc.com
They have several different products that would meet your needs in bridging java to .NET.
You can use the following API to run your .NET application via JNI.
Note, JVM and CLR co-existance in the same process is introduced in Java 6.0. I did not try to run it on the lower versions.
Re: Invoking C# program using .Net framework from a Java application
Dec 4, 2007 12:19 PM
(reply 10
of 10) (In reply to
#8 )
It is not pretty, but you can also run your C# code in a Windows Service, and have it listen on a socket.
When the Java program wants to invoke the C# code, it opens a socket to localhost, writes the parameters as a String (or whatever format you want). The C# code reads the String from the socket, performs the operations, and sends a response over the socket connection, where the Java program receives it.
The advantage of this approach is that you don't need a third party package. The disadvantages are you need a Windows Service, you have to worry about security (e.g., the C# code should make sure the connection is from localhost), and performance (setting up a socket is probably slower than making a JNI call).