Thursday, 22 November 2012

Using Java Jar or Class File in ASP.Net/ Convert Jar to dll

Using Java Jar or Class File in ASP.Net/ Convert Jar to dll


Even wondered how to use a Java or Jar file in .Net ?
Well, the answer can be complicated or it can be simple too.

Complicated - This way would be to deal with interops. You would have to load the JVM and then interop the java calls across.
Simple way - Use ikvm.net. Using ikvm we can convert java/jar file to a .net dll. And well then it’s all good and easy.
IKVM is a free tool and has a bunch of other Java-.Net related support.

How  It Works:

The ikvmc tool generates .NET assemblies from Java class files and jar files. It converts the Java bytecodes in the input files to .NET CIL. Use it to produce
  • .NET executables (-target:exe or -target:winexe)
  • .NET libraries (-target:library)
  • .NET modules (-target:module)
Java applications often consist of a collection of jar files. ikvmc can process several input jar files (and class files) and produce a single .NET executable or library. For example, an application consisting of main.jar, lib1.jar, and lib2.jar can be converted to a single main.exe.
When processing multiple input jar files that contain duplicate classes / resources, ikvmc will use the first class / resource it encounters, and ignore duplicates encountered in jars that appear later on the command line. It will produce a warning in this case. Thus, order of jar files can be significant.

Examples

ikvmc myProg.jar 
 
Scans myprog.jar for a main method. If found, an .exe is produced; otherwise, a .dll is generated.

ikvmc -out:myapp.exe -main:org.anywhere.Main -recurse:bin\*.class lib\mylib.jar
 
Processes all .class files in and under the bin directory, and mylib.jar in the lib directory. Generates an executable named myapp.exe using the class org.anywhere.Main as the main method.

For More Details Visit this Link:

 http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application

Alternatively,

http://www.jnbridge.com/

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top