简体   繁体   中英

JNA and Eclipse

I'm using JNA under Windows 64 bits / Eclipse Keplex (Java 6).

Though my program works as expected, when trying to debug under Eclipse, the exact same piece of code always fire an exception when I call one of the functions:

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)

I've setup jna.library.path variable and DLL is correctly found and mapped...

Again, if I run the exact same program outside of Eclipse, there are no problem at all.

Here is the interface for the library:

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);

}

Loaded this way, which works in both environments:

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

And as soon as I call one of the methods:

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

I get the exception (only in Eclipse, not in production)...

Add JNA lib directory in Native Library location of JRE on Eclipse.

  1. Right click on Eclipse project -> Build path -> Configure Build Path
  2. Open JRE System Library
  3. Click on Native lib location
  4. Edit
  5. Select JNA library location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM