Home Unable to get a native library (.so) to execute in grails 3
Reply: 0

Unable to get a native library (.so) to execute in grails 3

user5924
1#
user5924 Published in June 20, 2018, 1:35 am

I'm using a native library in my java code which is working perfectly through and through. When I use the same library in grails 3 application, it gets loaded fine, but when I call a native method, it throws UnsatisfiedLinkError exception.

I'm using following code in both cases:

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

For simple java code, it works fine with the relevant output. For same code in grails, it throws following exception. I tried to call the native function directly from groovy class as well as wrapping it up in a java class but to no avail. Stacktrace doesn't unveil any substantial debugging probes, but for completeness, here goes:

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)

What am I missing here?

Operating System: Ubuntu 16.04 with Linux 4.4.0-104-generic #127-Ubuntu x86_64 x86_64 x86_64 GNU/Linux

Grails Version: 3.2.2

JDK Version:

  • openjdk version "1.8.0_151"
  • OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
  • OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.554986 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO