如何在maven的java.library.path变量中包含本机库

kel*_*lly 11 native maven

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

只需运行带有以下命令的jar文件即可测试JNotify:java -Djava.library.path =.-jar jnotify-VER.jar [dir]

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

但是试图与maven一起工作并不成功.我试图运行一个简单的测试,但我得到以下错误

    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)        
Run Code Online (Sandbox Code Playgroud)

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

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

我已经将jar和.so添加到我们的内部存储库中

<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>
Run Code Online (Sandbox Code Playgroud)

这不起作用,任何想法丢失了吗?

谢谢

pru*_*nge 5

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

如果您需要将其命名为 jnotify.so,您可能需要尝试打开maven-dependency-plugin 复制目标的stripVersion选项。