Accessing .NET/dll libraries/components from Java?

后端 未结 6 860
-上瘾入骨i
-上瘾入骨i 2021-01-12 20:49

Are there inexpensive or free gateways from .NET to Java? I\'m looking at some data acquisition hardware which has drivers for C/C++ and .NET -- I really don\'t wan

相关标签:
6条回答
  • 2021-01-12 20:59

    Well, there's JNBridge and EZ JCom, just from a Google search.

    You could also use IKVM which is a slightly different approach.

    (Any reason for not wanting to learn .NET, out of interest? It's a nice platform, and C# is a lovely language...)

    0 讨论(0)
  • 2021-01-12 20:59

    If they have C++ versions of the drivers then you could write a wrapper around it using JNI and then load that in Java. JNI can be a bit of a pain, but it would let you use the C++ version of their drivers and not have to deal with .Net at all if you don't want.

    0 讨论(0)
  • 2021-01-12 21:14

    I am author of jni4net, open source interprocess 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.

    0 讨论(0)
  • 2021-01-12 21:17

    If you have a Java application, the JNI mentioned by the others will be the way to go. You write some wrapper classes, and that's it.

    If writing the wrappes is a too big task (depending on the number of methods you have to wrap), have a look at SWIG . I think it generates wrappers automatically, but I never actually used it.

    If you want to code in the Java language, but you don't care if your program will run on the JRE/JVM, then you might as well use Microsoft J#. Basically, it's writing Java-Code wich is compiled to .NET-Bytecode and can use the .NET classes of the driver as well as your existing Java classes. With J# you will run into problems if your existing Java-code is newer than Java 1.4, look at this question on how to solve them.

    From that point on, you could later add code in J#, C# or any other .NET language. However, you won't get back to the JRE/JVM easily.

    0 讨论(0)
  • 2021-01-12 21:22

    You could also try to use JNA for accessing the native library. JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code—no JNI or native code is required. If their API is fairly straight foward, this might be the path of least resistance.

    See their getting started guide where they call some native code (printf and GetSystemTime).

    0 讨论(0)
  • 2021-01-12 21:22

    I am partial to the recommendation to jump in the deep end with C# since it is so similar to Java. I did this and used IKVM to compile my favorite Java libs. to .NET assemblies and you get [nearly] all the core java runtime classes to boot, so if you tire of trying to find just the right C# collection type, you can always go back to java.util. (No generic collections though. Not sure why.)

    Depending on what platform you're on, you have several choices for free IDEs too. For windows you can get Visual Studio Express for free but I also use SharpDevelop. You can also get the Mono IDE on Linux (and a few flavours of Unix, I think ?).

    The C# learning curve is shallow if you already know Java. I only blew off 1.5 limbs on landmines that came out of nowhere for reasons I still don't understand, but workarounds were easy to come by. The worst thing about it was the darn developer docs which are AWFUL on account of being so slow. I really miss the snappiness of JavaDoc. Not only are the online docs incredibly slow, the problem is compounded by someones's iffy decision to put class summaries, constructors and methods/properties all on seperate pages so it just takes forever. Someone said to get the docs installer and install docs locally for a slightly improved experience. Not a bad idea I suppose.

    0 讨论(0)
提交回复
热议问题