如何在Maven的java.library.path变量中包含本机库 [英] How to include native library on maven's java.library.path variable

查看:150
本文介绍了如何在Maven的java.library.path变量中包含本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将JNotify用于我的应用程序,它具有以下要求

I am trying to use JNotify for my application , which has the following requirements

JNotify可以通过简单地运行带有以下命令的jar文件来进行测试: java -Djava.library.path =. -jar jnotify-VER.jar [dir]

JNotify can be tested by simply running the jar file with the followng commend: java -Djava.library.path=. -jar jnotify-VER.jar [dir]

然后,JNotify将监视指定的目录(如果未指定目录,则监视当前目录)并打印检测到的事件.请注意, java.library.path 应该指向jnotify附带的本机库的位置(dll,dylib等).

JNotify will then monitor the specified dir (or the current directory if dir is not specified) and print detected events. Note that java.library.path should point to the location of the native libraries that comes with jnotify (dlls, so dylibs etc).

但是,尝试使相同的东西与Maven一起工作并没有成功.我正在尝试运行一个简单的测试,但出现以下错误

But trying to get the same thing working with maven is not working out. I am trying to run a simple test but I get the following error

    java.lang.UnsatisfiedLinkError: no jnotify in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at net.contentobjects.jnotify.linux.JNotify_linux.<clinit>(Unknown Source)
    at net.contentobjects.jnotify.linux.JNotifyAdapterLinux.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)        

这意味着在库路径中找不到本机文件.

which means the native files are not found on the library path.

我的pom.xml看起来像这样-

My pom.xml looks like this -

我已将jar和.so添加到我们的内部资源库

I have added the jar and .so to our internal repository

<dependency>
            <groupId>net.contentobjects</groupId>
            <artifactId>jnotify</artifactId>
            <version>0.93</version>
</dependency>
<dependency>
           <groupId>net.contentobjects</groupId>
           <artifactId>jnotify</artifactId>
           <version>0.93</version>
           <type>so</type>
</dependency>


<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <configuration>
            <argLine>-Djava.library.path=target/lib/</argLine>
     </configuration>
</plugin>

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <executions>
       <execution>
              <id>copy</id>
              <phase>compile</phase>
              <goals>
                     <goal>copy</goal>
              </goals>
              <configuration>
                    <artifactItems>
                      <artifactItem>
                             <groupId>net.contentobjects</groupId>
                             <artifactId>jnotify</artifactId>
                             <version>0.93</version>
                             <type>so</type>
                             <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/lib</outputDirectory>
                     </artifactItem>
                     </artifactItems>
               </configuration>
             </execution>
          </executions>
 </plugin>

这是行不通的,有什么主意缺少吗?

This doesn't work though, any ideas whats missing?

谢谢

推荐答案

在编译阶段,依赖项.so文件是否已复制到目标目录中?命名正确吗?可能会将其命名为jnotify-0.93.so.

Does the dependency .so file get copied into the target directory in the compile phase? Is it named correctly? Likely it will be named something like jnotify-0.93.so.

如果您只需要命名为jnotify.so,则可能需要尝试打开

If you need it named just jnotify.so, you might want to tryt to turn on the stripVersion option of the maven-dependency-plugin's copy goal.

这篇关于如何在Maven的java.library.path变量中包含本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆