1

I want to call java API from c# code. My Java API is a jar file bundled with several 3rd party libraries. I am trying to use IKVM and JNI4Net. I am able to call few java functions but when code has dependency over 3rd party libs, it shows error: NoClassDefFoundError' occurred in dll. My question is it possible to execute java application (which is dependent on many 3rd party libs) from C# code using such JNI based tools?

amit
  • 181
  • 2
  • 4
  • 20

1 Answers1

0

Without being a jni4net expert, I have some experience doing just that. With jni4net, you need to use a BridgeSetup and call one of its AddClassPath() methods to build a classpath with your 3rd-party libraries.

For instance, something like this:

namespace My.Lib
{
  using System;
  using net.sf.jni4net;

  public static class MyClass
  {
    public static void Init()
    {
      // create the setup and register the Java classpath
      BridgeSetup bridgeSetup = new BridgeSetup(true);
      bridgeSetup.AddClassPath("lib/myLib1.jar");
      bridgeSetup.AddClassPath("lib/myLib2.jar");
      // add others ...

      // check the actual classpath we got
      Console.WriteLine("registered classpath : ");
      foreach (String s in bridgeSetup.JVMCLassPath) Console.WriteLine(s);

      // now create the JVM
      Bridge.CreateJVM(bridgeSetup);
    }
  }
}
Lolo
  • 4,277
  • 2
  • 25
  • 24
  • I am trying the same scenario from C#. I am not reaching to coding stage. It fails while generating proxies for my Jar file. Any idea? – amit May 12 '15 at 14:25