尝试运行 JAWT/JNI 应用程序。
我在 Windows 7 x64 上使用 jdk1.6.0_31 和MinGW64 。编译顺利,但仍然无法运行应用程序。JAWT_GetAWT()
在我添加功能之前没有问题。
问题是我是 C/C++ 编程语言的新手。
本机.java
import java.awt.Component;
import javax.swing.JFrame;
public class Native{
static {
System.loadLibrary("native");
}
public static native boolean getBoolean(Component component);
public static void main(String args[]){
JFrame frame = new JFrame("test viewport");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
getBoolean(frame);
}
}
生成的 Native.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Native */
#ifndef _Included_Native
#define _Included_Native
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Native
* Method: getBoolean
* Signature: (Ljava/awt/Component;)Z
*/
JNIEXPORT jboolean JNICALL Java_Native_getBoolean
(JNIEnv *, jclass, jobject);
#ifdef __cplusplus
}
#endif
#endif
本机.c
#include <jni.h>
#include <jawt_md.h>
#include <jawt.h>
#include "Native.h"
JNIEXPORT jboolean JNICALL Java_Native_getBoolean(JNIEnv *env, jclass class, jobject component){
JAWT awt;
awt.version = JAWT_VERSION_1_4;
return JAWT_GetAWT(env, &awt);//can't run after I add this function
}
来自这里的GCC 编译命令行
gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -Id:/devtools/java/jdk1.6.0_31/include -Id:/devtools/java/jdk1.6.0_31/include/win32 -LD:/devtools/java/jdk1.6.0_31/jre/bin -ljawt -shared Native.c -o native.dll
应用程序给出 java.lang.UnsatisfiedLinkError:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\t.key\Desktop\Native\native.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at Native.<clinit>(Native.java:7)
Could not find the main class: Native. Program will exit.
请帮忙!