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.
Most of the time (if not always) when you create an API, it is in a jar (refer twitter API, facebook API, google API and so on).
The JD-GUI is a nice open-source GUI utility to explore Java source code decompiled by the Java decompiler JD-Core. When we see the main window of JD-GUI, we can either open our JAR file by navigating the menu “File -> Open File…” or just drag-and-drop the JAR file in the window.
You can do it using IVKM.Net. IVKM.NET includes an application called ikvmc. Here’s the documentation for this tool:
http://www.ikvm.net/userguide/ikvmc.html
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With