By timmyg

2009-02-04 16:28:42 8 Comments

I'm an entry level programmer so please be descriptive in your responses.

I am trying to use a Java API given as a .jar file in my C# .net application. I don't know much Java, but this .jar file says "no main-class manifest attribute" when I try to run it so this means its a library? This Java API also comes with a .java file which shows how to use the library but I cannot see the code inside the .jar.

I found this question on this site, and one of the answers reads, "In simple way you can pack your java classes to jar file then In C# use Process class for execute and map IO stream." I am semi-familiar with the Process class in C# but I don't understand how I could use it to use a Java library in my C# .net project.

Is this possible? or was that answer incorrect?

If so, could you explain how I can use the .jar library in my C# app.


@Maciej Pulikowski 2020-01-01 14:23:05

  1. You could use IKVM.NET -

    On the official website in download - you can get ikvmbin-7.2.4630.5 (Works up to Java 7)

    However, on the owner's blog, you can download a newer version. - You can get ikvmbin-8.1.5717.0 (Works up to Java 8)

    To create dll/exe use:

    ikvmc hello.jar

  2. On the other hand, if you can edit .jar lib (you created it) you could use project.

@Stephen Curial 2009-02-04 16:58:39

You can do it using IVKM.Net. IVKM.NET includes an application called ikvmc. Here’s the documentation for this tool:

To use it compile your java code into a Jar.

Then run the ikvmc program:

ikvmc myCode.jar

If your jar contains a main() function, it will be converted into an exe that can be run on the CLR. Otherwise it will be converted into dll’s. To use the dll’s in your project just add them as references in Visual Studio and the same API that was available to you in Java will be accessible in your .Net application.

You can also include the IKVM.GNU.Classpath.dll dll from ikvmc and use the standard java class libraries in your application.

@timmyg 2009-02-04 17:49:52

thanks I will give it a try. once i have the .dll and I import it into my project should I call the library's function using Pinvoke?

@Stephen Curial 2009-02-04 18:10:10

You don't need to use pinvoke. You should be able to simply call the api just like you would as if it was orig written in C#.

@LDomagala 2009-02-04 19:52:45

you should change "run on the CIL" into "run on the CLR"

@timmyg 2009-02-04 21:02:56

It Worked! Thanks again!

@Cragly 2010-04-22 09:40:01

Good stuff, just used it in my .net app and worked like a charm. Thanks

@Joel B 2012-02-08 02:22:35

I'm pretty sure you just made me an office hero.

@andrej 2012-05-17 16:19:06

I just created dll from my jar but I can see no functions using depwalker. Is this normal behavior?

@Rad 2009-02-04 17:04:30

Have a look at IKVM ... it has tools to give you some level of interop. When you say Java API I assume you want to call some functionality from the jar rather than just execute it

@timmyg 2009-02-04 17:52:12

Correct, the .jar doesn't execute, it reports an error message that reads, "Failed to load Main-Class manifest attribute from ...". Once I have the .jar converted to .dll I'm going to attempt to use it the same as the java coded example using the .jar.

Related Questions

Sponsored Content

11 Answered Questions

[SOLVED] What are the correct version numbers for C#?

66 Answered Questions

[SOLVED] How do I generate random integers within a specific range in Java?

  • 2008-12-12 18:20:57
  • user42155
  • 4059323 View
  • 3507 Score
  • 66 Answer
  • Tags:   java random integer

27 Answered Questions

[SOLVED] Why not inherit from List<T>?

87 Answered Questions

[SOLVED] Is Java "pass-by-reference" or "pass-by-value"?

32 Answered Questions

[SOLVED] When to use LinkedList over ArrayList in Java?

57 Answered Questions

[SOLVED] How to create a memory leak in Java?

37 Answered Questions

[SOLVED] Can't execute jar- file: "no main manifest attribute"

64 Answered Questions

[SOLVED] What is the difference between String and string in C#?

59 Answered Questions

[SOLVED] How do I read / convert an InputStream into a String in Java?

39 Answered Questions

Sponsored Content