Use a DLL generated by IKVM - java

I have generated a DLL froma JAR file using IKVM doing:
ikvmc -target:library mylib.jar
I would like to use the DLL in a Visual C++ project. What are the steps required to call dll functions from my own code? How do I know which methods are exported by the DLL and how do I call them without a header file?

The IKVM.NET is written for the .NET framework 2.0. The usage inside a Visual Studio C++ project can be difficult. But it should be possible to access it via COM interface. Take a look at this answer.

Related

How to access jar file through Xamarin Forms

I have a Xamarin project and an android bindings library that has a jar file attached. How can I call a function from the jar library. For example, so that when a button is pressed, a function from the library is called.
Sample project:
For this, you can check document Binding a .JAR.
The Android community offers many Java libraries that you may want to use in your app. These Java libraries are often packaged in .JAR (Java Archive) format, but you can package a .JAR it in a Java Bindings Library so that its functionality is available to Xamarin.Android apps. The purpose of the Java Bindings library is to make the APIs in the .JAR file available to C# code through automatically-generated code wrappers.
Xamarin tooling can generate a Bindings Library from one or more input .JAR files. The Bindings Library (.DLL assembly) contains the following:
The contents of the original .JAR file(s).
Managed Callable Wrappers (MCW), which are C# types that wrap
corresponding Java types within the .JAR file(s).
The generated MCW code uses JNI (Java Native Interface) to forward your API calls to the underlying .JAR file. You can create bindings libraries for any .JAR file that was originally targeted to be used with Android (note that Xamarin tooling does not currently support the binding of non-Android Java libraries). You can also elect to build the Bindings Library without including the contents of the .JAR file so that the DLL has a dependency on the .JAR at runtime.
For more information, you can check: Binding a Java Library .

Building cross-platform(Linux, Windows) java JNI application with maven

I want to build Java application which uses JNI and code in C. Moreover I want make my app cross-platform by compiling native code and packaging native platform-dependent libraries within JAR file. I was following this guide
but it is not working. I have no examples with maven-native-plugin nor NAR plugins. How is it possible to make java native methods cross-platform?
I would suggest to check the nar-maven-plugin for example.

to include dll file in java without jar files

I have to include .net "SMSMiracle.dll" in java. I don't have any jar files. I imported the dll file to the project using System.loadLibrary(). Tell me how to call the files in java?
thanks in advance
You need to use JNI or better use a library like Java Native Access

Is there a way to include native libraries in a JAR, like in Java Webstart, without using Webstart?

I'm working on a game that uses LWJGL and thus requires native libraries specific to each platform. On this page, the author shows how to use the <nativelib> tag with Java Webstart to include JARs containing the appropriate native libraries. I'm trying to do something similar, but without using Webstart.
I tried adding the native library JARs to my main executable JAR's classpath, but that didn't work. Currently, the native libraries just sit in the same directory as the main JAR and that works fine, but I'd like to make it a bit tidier.
You have to use the JVM argument -Djava.library.path=/path/to/libs
Generate your jar, then add a script containing something like the following:
#!/bin/bash
java -Djava.libraray.path=. -jar your.jar
Asserting that the native libs are placed in the same folder as your application jar file.

How can I include platform-specific native libraries in the .JAR file using Eclipse?

I am just starting to learn JNI. I have been following a simple example, and I have created a Java app that calls a Hello World method in a native library. I'd like to target Win32 and Linux x86.
My library resides in a DLL, and I can call it just fine using LoadLibrary when the DLL is added to the root of my Eclipse project.
However, I can't figure out how to get Eclipse to export a runnable JAR that includes the DLL and the .SO file for Linux.
So my question is basically; how would you go about creating a project in Eclipse and include several versions of the same native library?
Thank you,
Martin
For runnable JARs, what you need to do is extract to the temporary directory (maybe in a static { } block) and then load the DLL from that directory (using System.loadLibrary() in the same block). To do this, you need to subclass ClassLoader and override the findLibrary() method to allow libraries to be found in that directory. You can do whatever logic you need to here to load the particular platform libraries. To be honest, the naming for the libraries on the different platforms should be similar anyway -- I believe that you omit the 'lib' part when loading, and the extension. That's the gist of it. Probably easier to use One-JAR as the other poster mentioned :)
You might want to check out the One-JAR project. It lets you package your application and its dependencies (including native libraries) to a single jar file.

Categories