Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i have to call c# file/program from java program how to do it ?

 
kulbhushan patil
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me how to run c# file through java program
 
Smitesh Shinde
Ranch Hand
Posts: 45
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know C# produces exe file after the compilation. You can exeute the .exe files from a java program as if it is executed from commandline. Do research on how to exeute commands in java.

If you are looking for calling particular method in your C# from java then I believe web services is the only way.
 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. To start C# program, just exec() it. A C# program is just another executable.

To communicate with an already running program, web-services is an option, but so are files, network sockets, and any form of IPC.


And finally, to call a function that was written in C# (or any .NET library function) from Java, you can use JNI. However, all JNI will do is get you to C/C++, or in Microsoft speak, to Unmanaged C++ -- you will need to write a simple Managed C++ object that can forward request from the unmanaged side to the .NET library.

Henry
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the project I'm currently working on, we use a library for this: JuggerNET. It isn't always easy to use, though - especially because of the conversion of Java objects to C# objects and vice versa.
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We all know, of course, that you never go near exec() until you have read the classic article by Michael Daconta, "When runtime.exec() won't".
And I think this is too difficult for "beginning", so shall move the thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic