简体   繁体   中英

How to include shared object files in maven project

I am using an external c++ library (gdal/ogr) which creates shared object files so that java can utilize its functionality. The problem is that I am not really sure what I am supposed to do with these .so files and how I am supposed to get maven to use them when building the project. I found this tutorial on how to include shared object files

but when I follow the directions given, I just get this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at org.lwjgl.Sys$1.run(Sys.java:73)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
    at org.lwjgl.Sys.loadLibrary(Sys.java:95)
    at org.lwjgl.Sys.<clinit>(Sys.java:112)
    at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
    at com.googlecode.nativedependencies.example.App.main(App.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

For context on the relevant .so files and how they are generated, see the following link on compiling gdal/ogr with java bindings.

I am just looking for the most robust way to include these files so that I can, to the greatest extent possible, use the gdal/ogr library in java the way I would any other normal java library.

I think this plugin help you build java project. But you still needs to inform JVM where are the native files.

See How to add native library to “java.library.path” with Eclipse launch (instead of overriding it) or simple one How to Load a Java Native/Shared Library (.so)

You need to override (in the same console before you open eclipse or run your java program)

export LD_LIBRARY_PATH = "${workspace_loc}/lib:${LD_LIBRARY_PATH}"

or add to java command:

-Djava.library.path="${workspace_loc:project}\lib;${env_var:PATH}"

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