我使用Java + Jersey + JNA(https://mvnrepository.com/artifact/net.java.dev.jna/jna/4.5.2) 在Delphi中访问DLL文件。
我的操作系统是Windowns 10(64位)。 该dll以64位元生成。
我只是试图访问Java中的DLL方法。
Java的代码是:
DllSimples.java
import com.sun.jna.Library;
import com.sun.jna.Native;
public interface DllSimples extends Library{
String testar();
}
TesteService.java
public Response chamaDll() {
DllSimples calculadora = (DllSimples)
Native.loadLibrary("teste", DllSimples.class);
String parametro = calculadora.testar();
MensageiroDTO mensagem = new MensageiroDTO(parametro);
return Response.ok(mensagem).build();
}
pom.xml
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.2</version>
</dependency>
错误:
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.Error: Invalid memory access
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:432)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
org.glassfish.jersey.server.ContainerException: java.lang.Error: Invalid memory access
org.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:278)
org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:260)
org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:460)
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:285)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
注意:该DLL已预先在DELPHI语言中进行了测试,并且正在运行。