5

I'm wondering if a Java library can be called from a VB.net application.

(A Google search turns up lots of shady answers, but nothing definitive)

David Koelle
  • 19,986
  • 23
  • 89
  • 126

8 Answers8

4

No, you can't. Unless you are willing to use some "J#" libraries (which is not nearly the same as Java) or IKVM which is a Java implementation that runs on top of .NET, but as their documentation says:

IKVM.OpenJDK.ClassLibrary.dll: compiled version of the Java class libraries derived from the OpenJDK class library with some parts filled in with code from GNU Classpath and IcedTea, plus some additional IKVM.NET specific code.

So it's not the real deal.

dguaraglia
  • 5,274
  • 1
  • 22
  • 23
  • +1 for IKVM we use it to nicely communicate between our .NET UI and Java server via RMI stubs wrapped by IKVM assemblies. – Matt Sep 30 '08 at 14:06
  • Indeed, IKVM does the job nicely as long as the components aren't AWT/Swing based. – jsight Sep 30 '08 at 15:24
3

I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.

Pavel Savara
  • 3,277
  • 26
  • 33
2

You can call Java from .NET if you wrap it in some form to make it accessable and the easiest way is typically to use a Runtime bridge like

http://www.jnbridge.com/

Other way is to wrap your API with java webservices.

check this also http://www.devx.com/interop/Article/19945

user18834
  • 49
  • 1
  • 4
1

Nothing out of the box.

Most java/.net interop that I know uses web services.

jop
  • 77,529
  • 10
  • 52
  • 52
1

If you can create COM components with Java, you can use tlbimp to create an interop assembly for using in VB.Net.

If can create standard DLLs that can be used from C++ with Java, you can write P/Invoke declarations and call them from VB.Net.

If you can create a web service with Java, you can generate proxy class from the WSDL and call it from VB.Net.

In any case, chances are the Java component will live in a separate process. I doubt you can load both the Java VM and the CLR in the same process.

Franci Penov
  • 71,783
  • 15
  • 124
  • 160
1

If you have the source code and compile it using the J# compiler, then the answer is yes. If you want to call any pre-Java 2 (aka 1.2) libraries, then these are included pretty much verbatim with J#. More recent stuff is going to be tricky though (i.e., it's not there).

An example where this is used commercially are the yFiles graph layout algorithms from yWorks. These were originally just a Java library, but for the past few years they've been offering a .NET version, which is just the Java version compiled with Visual J#.

It's not without problems, and there are some limitations that you can't get around, but it can be done. So... unfortunately this answer looks pretty shady as well.

Bart Read
  • 2,549
  • 2
  • 20
  • 29
0

You could use JNI to instantiate a virtual machine and then use Java Classes. It will be some fun, though, because you would need to use C++ as a bridge between VB.Net and Java.

This article in java world has a quick tutorial on how to use Java from C++ and viceversa.

http://www.javaworld.com/javaworld/javatips/jw-javatip17.html

Mario Ortegón
  • 17,860
  • 17
  • 67
  • 79
0

If you have the source, Visual Studio will let you convert Java code into c#.

StingyJack
  • 17,990
  • 7
  • 58
  • 115