Reputation: 436
I have simple question but I couldn't find an answer ;/ How can I create and call assembler library inside java project? I have found something like this to call created library:
public class Hello {
public static void main(String[] args) {
System.out.println("start");
System.loadLibrary("native");
(new Hello()).nativeCode();
System.out.println("stop");
}
public native void nativeCode();
}
but solution to create library is based on linux so I cant figure out how to do it on win 7 64 bit. Do you have any ideas? Thanks from advice.
Upvotes: 1
Views: 509
Reputation: 34581
Calling native code from Java is accomplished using JNI. You'll need to write a Java class that includes method(s) declared using the native
keyword, and in your native library you'll need to include a corresponding function with the appropriate name and parameters for the JVM to call.
Since the native function called by the JVM takes arguments whose types are defined in the C header jni.h
, and you interact with the JVM by calling C functions declared in that same header, you'll probably find it easiest to write some C (or C++) code of your own to act as an intermediary between the JVM and your assembler code.
The details of how to actually build the native library are platform-specific, but not Java-specific; on Windows, Java's System.loadLibrary()
just loads ordinary DLL files. Your compiler/assembler documentation should provide information on how to build one.
Upvotes: 2