JNI UnsatisfiedLinkError [英] JNI UnsatisfiedLinkError
问题描述
我想创建一个简单的JNI图层。我使用Visual Studio 2008创建一个dll(Win 32控制台应用程序项目类型与DLL作为选项)。当我调用本地方法时,得到这个异常:
事件分派期间发生异常:
java.lang.UnsatisfiedLinkError :com.tpd.vcdba.console.TaskScheduler.vcdbaTaskSch
edulerNative.Hello()V
在com.tpd.vcdba.console.TaskScheduler.vcdbaTaskSchedulerNative.Hello(钠
略去法)
。在com.tpd.vcdba.console.TaskScheduler.vcdbaTaskSchedulerUtil.isTaskExis
TS(vcdbaTaskSchedulerUtil.java:118)
。在com.tpd.vcdba.console.Dialogs.schedulerWizardPage.scheduleTaskPage.wz
完成(scheduleTaskPage.java:969)
at com.tpd.vcdba.console.wizard.vcdbaWizard.gotoFinish(vcdbaWizard.java:
434)
at com.tpd.vcdba .console.wizard.wzActionPanel.actionPerformed(wzActionPa
nel.java:163)
at javax.swing.AbstractButton.fireActionPerformed(未知来源)
生成的头文件是:
/ *这个文件 - 它是机器生成的* /
#include< jni.h>
/ *头类com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative * /
的#ifndef _Included_com_tpd_vcdba_console_TaskScheduler_
vcdbaTaskSchedulerNative
的#define _Included_com_tpd_vcdba_console_TaskScheduler_
vcdbaTaskSchedulerNative
的#ifdef __cplusplus
为externC{
#ENDIF
/ *
*类别:com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative
*的方法:你好
*签名:()V
* /
JNIEXPORT void JNICALL Java_com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative_Hello
(JNIEnv *,jobject);
#ifdef __cplusplus
}
#endif
#endif
实现文件是:
#pragma once
#includecom_tpd_vcdba_console_TaskScheduler_
vcdbaTaskSchedulerNative.h
的#includestdafx.h中
的#includejni.h
/ *
*类别:com_tpd_vcdba_console_TaskScheduler_vcdbaTaskScheduler_native
*方法:你好
*签名:()V
* /
JNIEXPORT无效JNICALL Java_com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative_Hello
(的JNIEnv * ENVS,jobject OBJ){
的printf(世界你好 );
}
java文件是:
package com.tpd.vcdba.console.TaskScheduler;
import com.tpd.vcdba.console.TaskScheduler.ScheduleTask;
public class vcdbaTaskSchedulerNative {
public native void Hello();
private static vcdbaTaskSchedulerNative instance = null;
static {
try {
System.loadLibrary(JNITrial);
}
catch(例外){
}
}
public vcdbaTaskSchedulerNative
}
公共静态vcdbaTaskSchedulerNative的getInstance(){
如果(例如== NULL){
实例=新vcdbaTaskSchedulerNative();
}
return instance;
}
}
当我调用本地方法另一件我注意到的是,当我在命令行中编译时使用:
cl -IC:\Program文件(x86)\Java\jdk1.7.0\include-IC:\Program文件(x86)\Java\jdk1.7.0\include\win32-LDC:\ Users\administrator.RMDOM\Documents\Visual工作室2008\Projects\JNITrial\JNITrial\JNIInt.cpp-FeJNITrial.dll,
一切工作正常。
我在Visual Studio设置中缺少什么?我有选项使用MFC作为在共享DLL中使用MFC,代码生成选项为多线程DLL(/ MD)。它的64位dll。
是否还有其他的东西需要添加?
欢迎任何帮助。
提前感谢。
我想出了解决方案。
我的项目使用了precompiled headers选项集,因此编译器跳过了以下语句:
#includecom_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative.h
魔法。
I want to create a simple JNI layer. I used Visual studio 2008 to create a dll (Win 32 Console Application project type with DLL as the option). Im getting this exception when I invoke the native method:
Exception occurred during event dispatching:
java.lang.UnsatisfiedLinkError: com.tpd.vcdba.console.TaskScheduler.vcdbaTaskSch
edulerNative.Hello()V
at com.tpd.vcdba.console.TaskScheduler.vcdbaTaskSchedulerNative.Hello(Na
tive Method)
at com.tpd.vcdba.console.TaskScheduler.vcdbaTaskSchedulerUtil.isTaskExis
ts(vcdbaTaskSchedulerUtil.java:118)
at com.tpd.vcdba.console.Dialogs.schedulerWizardPage.scheduleTaskPage.wz
Finish(scheduleTaskPage.java:969)
at com.tpd.vcdba.console.wizard.vcdbaWizard.gotoFinish(vcdbaWizard.java:
434)
at com.tpd.vcdba.console.wizard.wzActionPanel.actionPerformed(wzActionPa
nel.java:163)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
The header file generated is :
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative */
#ifndef _Included_com_tpd_vcdba_console_TaskScheduler_
vcdbaTaskSchedulerNative
#define _Included_com_tpd_vcdba_console_TaskScheduler_
vcdbaTaskSchedulerNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative
* Method: Hello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative_Hello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
The implementation file is:
#pragma once
#include "com_tpd_vcdba_console_TaskScheduler_
vcdbaTaskSchedulerNative.h"
#include "stdafx.h"
#include "jni.h"
/*
* Class: com_tpd_vcdba_console_TaskScheduler_vcdbaTaskScheduler_native
* Method: Hello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative_Hello
(JNIEnv *envs, jobject obj){
printf("hello world");
}
The java file is:
package com.tpd.vcdba.console.TaskScheduler;
import com.tpd.vcdba.console.TaskScheduler.ScheduleTask;
public class vcdbaTaskSchedulerNative {
public native void Hello();
private static vcdbaTaskSchedulerNative instance = null;
static{
try{
System.loadLibrary("JNITrial");
}
catch(Exception ex){
}
}
public vcdbaTaskSchedulerNative(){
}
public static vcdbaTaskSchedulerNative getInstance(){
if(instance == null){
instance = new vcdbaTaskSchedulerNative();
}
return instance;
}
}
When I invoke the native method "Hello" i get the execption.
Another thing I observed is that when I compile in command line using: "cl -I"C:\Program Files (x86)\Java\jdk1.7.0\include" -I"C:\Program Files (x86)\Java\jdk1.7.0\include\win32" -LD "C:\Users\administrator.RMDOM\Documents\Visual Studio 2008\Projects\JNITrial\JNITrial\JNIInt.cpp" -FeJNITrial.dll" , everything works fine.
Am I missing out something in Visual Studio Settings? I have option Use of MFC as "Use MFC in a Shared DLL", Code generation option as "Multi-threaded DLL (/MD)". Its a 64 bit dll. Is there something else that I need to add?
Any help is welcome. Thanks in advance.
I figured out the solution.
My project had use precompiled headers option set, so the compiler was skipping the statement:
#include "com_tpd_vcdba_console_TaskScheduler_vcdbaTaskSchedulerNative.h"
Once I removed that option it worked like magic.
这篇关于JNI UnsatisfiedLinkError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!