2014-03-07 86 views
1

我在Windows 64位/ Eclipse Keplex(Java 6)下使用JNA。JNA和Eclipse

雖然我的程序正常工作,試圖在Eclipse的調試時,完全相同的一段代碼總是觸發一個例外,當我打電話的功能之一:

java.lang.Error: Invalid memory access 
    at com.sun.jna.Native.invokeInt(Native Method) 
    at com.sun.jna.Function.invoke(Function.java:344) 
    at com.sun.jna.Function.invoke(Function.java:276) 
    at com.sun.jna.Library$Handler.invoke(Library.java:216) 

我設置jna.library.path變量, DLL被正確地找到並映射出來...

同樣,如果我在Eclipse之外運行完全相同的程序,則完全沒有問題。

下面是該庫的接口:加載這樣

public interface FKCOMM extends StdCallLibrary { 
public final static int FK_COMM_MAX_STAT_CODES    = 100; 
public final static int STIL_MD5_KEY_LEN     = 36; 

int FofInit(String host, String service, int openNow, LpFof pSrvFof); 
int FofClose(Fof srvFof); 
Fof FofLast(); 
int FofClear(Fof srvFof); 
int FofExecGetOrigins(Fof srvFof); 

int FofExecFml(Fof serv, String appcode, String usercode, String format, String inout, String type, 
       String reference, String sender, String receiver, String amount, String currency, 
       String currency2, String unit, String userdata, String service, String mur, 
       String vflag, String message, int details); 
int FofExec(Fof srvFof, int mode, String field, String icn, String mtype, String unit, int details); 
int FofExecFmlSimple(Fof serv, String appCode, String userCode, String mode, String unit, String userData, String message, int details); 
int FofExecFmt(Fof serv, int i, String c1, String c2, String c3, String c4, String c5, String c6, int i2); 

int FniExecBuildBuffer(Fni srvFni, Fof srvFof, String text, char ioIndicator, String businessType, 
     String messageId, String messageType, String format, String amount, String currency, String senderReference, 
     String entity, String appCode, int detailAlertP, PointerByReference pBuffer, PointerByReference pLen, 
     String sender, String receiver, String addInfo, String itvTxt); 

int FofExecGetRecord(Fof serv, String recordId); 
int FkCommTraceOn(String path, String name, int LogicalMode); 
int FofSetCaller(Fof serv, String caller); 
int FofExecSrvReady(Fof serv); 

}

,這兩種環境中的工作原理:

library = (FKCOMM) Native.loadLibrary("FKCOMM", FKCOMM.class); 

而且只要我打電話的一個方法:

result = library.FofExecFmt(session, 1, settings.getFormatName(), data, "", settings.getApplicationId(), request.getId(), "", request.isWithDetails() ? 1 : 0); 

我得到異常(僅在Eclipse中,不在生產中)...

回答

1

在Eclipse的JRE本機庫位置添加JNA lib目錄。

  1. 在Eclipse項目右鍵 - >構建路徑 - >配置構建路徑
  2. 打開JRE系統庫
  3. 點擊本地庫位置
  4. 編輯
  5. 選擇JNA庫的位置