How can I Import a *.so file into a *.jar while using Maven build tools?

108 Views Asked by At

How can I Import a *.so file into a *.jar while using Maven build tools? And could load that *.so file?

considering convenience of the deployment usage.

I want to load native methods from *.so then run business code... When I packaged jar file and run the app by shell automaticly. But it didn't work in linux.

java -jar demo.jar -server -Dfile.encoding=UTF-8 -Dspring.profiles.active=prod

System.loadLibrary("mylib");

It can load the dll file in the WINDOS's development successfully。

` //Windows

ClassLoader cl = SyWorkflowController.class.getClassLoader();

URL url = cl.getResource("//");

String path = url.getPath();

System.load(path+"mylib.dll");

`

But in the Linux is error (deployment usage). when using the packaged jar file, can not found the URL. I found the JVM OPTS 'java.class.path' only represented 'demo.jar'.

` //Linux

ClassLoader cl = SyWorkflowController.class.getClassLoader();

URL url = cl.getResource("//");   //url is null. occur an error

String path = url.getPath();

System.load(path+"mylib.so");

`

When I realsed a demo.jar project and use java cli to run the demo application, I found the JVM OPTS 'java.class.path' only represented 'demo.jar'.

I tried to package my *.so file into the demo.jar (path:\BOOT-INF\lib) manually and run the application again. However fails again.

Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/libmylib.so

0

There are 0 best solutions below