如何在 maven 的 java.library.path 变量上包含本机库
我正在尝试为我的应用程序使用 JNotify,它有以下要求
只需使用以下命令运行 jar 文件即可测试 JNotify: java -Djava.library.path=. -jar jnotify-VER.jar [目录]
然后,JNotify 将监视指定的目录(如果未指定目录,则监视当前目录)并打印检测到的事件。请注意,java.library.path 应指向 jnotify 附带的本机库的位置(dll、dylib 等)。
但试图用 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)
,这意味着在库路径上找不到本机文件。
我的 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>
但这不起作用,有什么想法缺少什么吗?
谢谢
I am trying to use JNotify for my application , which has the following requirements
JNotify can be tested by simply running the jar file with the followng commend:
java -Djava.library.path=. -jar jnotify-VER.jar [dir]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).
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.
My pom.xml looks like this -
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?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
依赖项 .so 文件是否在编译阶段复制到目标目录中?它的命名正确吗?它可能会被命名为 jnotify-0.93.so。
如果您需要将其命名为 jnotify.so,您可能需要尝试打开 stripVersion 选项。
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.
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.