3

Possible Duplicate:
Use a .jar java library API in C#?

I have a jar file I want to run in a C# application, is there anyway to do this?

Community
  • 1
  • 1
Nurdism
  • 578
  • 1
  • 9
  • 20
  • 1
    http://stackoverflow.com/questions/512124/use-a-jar-java-library-api-in-c – Damith Sep 05 '11 at 20:26
  • [How to execute a Java program from C#?](http://stackoverflow.com/questions/873809/how-to-execute-a-java-program-from-c) – Damith Sep 05 '11 at 20:35

3 Answers3

6

You could use the ikvmc.exe compiler to generate a .NET assembly from this .jar:

ikvmc.exe -target:library -out:Foo.dll Foo.jar

This will generate Foo.dll. From now on you know what to do with the managed Foo.dll assembly.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • The op says he wants to run the .jar file, not use it as a library. – Marcelo Sep 05 '11 at 20:31
  • @Marcelo, what makes you think that the .jar contains a `main` method? Of course if this was the case the OP could read the documentation of the article I have linked to in my answer and use `ikvmc.exe -target:exe -out:Foo.exe Foo.jar` and then run `Foo.exe`. – Darin Dimitrov Sep 05 '11 at 20:32
1

You can use IKVM.

From the Uses for IKVM.NET page:

Use Java libraries in your .NET applications

IKVM.NET includes ikvmc, a Java bytecode to .NET IL translator. If you have a Java library that you would like to use in a .NET application, run ikvmc -target:library mylib.jar to create mylib.dll.

For example, the Apache FOP project is an open source XSL-FO processor written in Java that is widely used to generate PDF documents from XML source. With IKVM.NET technology, Apache FOP can be used by any .NET application.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

Use this line :

System.Diagnostics.Process.Start("java -jar filename.jar");

If you want these java and c# to interact with each other use shared file or socket programming

Note you need to configure java in ur system.