我在我的java代码中使用了一个本机库,它完美地贯穿始终。当我在grails 3应用程序中使用相同的库时,它可以很好地加载,但是当我调用本机方法时,它会抛出UnsatisfiedLinkError
异常。
我在两种情况下都使用以下代码:
try{
System.loadLibrary("TrippleDes")
String plainText = "passw0rd.!";
String cipher = JniWrapper.encrypt(plainText);
String orgStr = JniWrapper.decrypt(cipher);
System.out.println("Original text: " + plainText);
System.out.println("Cipher text: " + cipher);
System.out.println("Restored text: " + orgStr);
}catch (Exception ex){
System.out.println(ex.getMessage());
}
对于简单的java代码,它可以与相关输出一起使用。对于grails中的相同代码,它会抛出异常。我试图直接从groovy类调用本机函数,并将其包装在java类中,但无济于事。 Stacktrace没有公布任何实质性的调试探针,但为了完整性,这里有:
java.lang.UnsatisfiedLinkError: com.ef.apps.licensing.JniWrapper.encrypt(Ljava/lang/String;)Ljava/lang/String;
at com.ef.apps.licensing.JniWrapper.encrypt(Native Method)
at com.ef.apps.licensing.licCheck.check(licCheck.java:7)
at com.ef.apps.licensing.licCheck$check.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at umm1.BootStrap$_closure1.doCall(BootStrap.groovy:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1125)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1089)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1125)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:408)
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:516)
at grails.util.Environment.executeForEnvironment(Environment.java:509)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:485)
at org.grails.web.servlet.boostrap.DefaultGrailsBootstrapClass.callInit(DefaultGrailsBootstrapClass.java:62)
at org.grails.web.servlet.context.GrailsConfigUtils.executeGrailsBootstraps(GrailsConfigUtils.java:65)
at org.grails.plugins.web.servlet.context.BootStrapClassRunner.onStartup(BootStrapClassRunner.groovy:53)
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:256)
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:877)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at grails.boot.GrailsApp.run(GrailsApp.groovy:79)
at grails.boot.GrailsApp.run(GrailsApp.groovy:381)
at grails.boot.GrailsApp.run(GrailsApp.groovy:370)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at umm1.Application.main(Application.groovy:8)
我在这里错过了什么?
操作系统:Ubuntu 16.04 with Linux 4.4.0-104-generic#127-Ubuntu x86_64 x86_64 x86_64 GNU / Linux
Grails版本:3.2.2
JDK版本:
Groovy使用不同于java的类加载器。您必须按照以下方向进行锻炼:1。加载库时,明确告知要使用哪个加载程序。 2.在Grails中分叉JVM,以便它使用具有该库集路径的加载器。
这是Grails 2 qazxsw poi的类似问题
我想知道你走了哪条路,你如何在Grails3中解决。