简体   繁体   English

如何在Maven项目中包括共享对象文件

[英]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. 我正在使用一个外部c ++库(gdal / ogr),该库创建共享对象文件,以便java可以利用其功能。 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. 问题是我不确定我应该如何处理这些.so文件,以及在构建项目时如何让Maven使用它们。 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. 有关相关.so文件的上下文以及它们的生成方式,请参阅以下有关使用java绑定编译gdal / ogr的链接

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. 我只是在寻找包含这些文件的最健壮的方法,以便可以在最大程度上使用java中的gdal / ogr库,就像使用其他任何普通java库一样。

I think this plugin help you build java project. 我认为这个插件可以帮助您构建Java项目。 But you still needs to inform JVM where are the native files. 但是您仍然需要通知JVM本机文件在哪里。

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) 请参阅如何通过Eclipse启动(而不是覆盖)将本机库添加到“ java.library.path”或简单的方法如何加载Java本机/共享库(.so)

You need to override (in the same console before you open eclipse or run your java program) 您需要重写(在打开eclipse或运行Java程序之前,请在同一控制台中进行重写)

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

or add to java command: 或添加到Java命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM