简体   繁体   English

如何在2.1 RC2中包含本机库(JNI)?

[英]How to include native library (JNI) in play 2.1 RC2?

I am using Play Framework 2.1 RC2 to build an application that utilizes TFS Java SDK . 我正在使用Play Framework 2.1 RC2来构建一个使用TFS Java SDK的应用程序。 TFS APIs require a set of native dlls (eg native_auth.dll ) to be included. TFS APIs需要包含一组本机dll(例如native_auth.dll )。

How do I make the native libraries available when the application is running? 如何在应用程序运行时使本机库可用? Where can I specify the native dlls to be included? 我在哪里可以指定要包含的本机dll?

Update: I tried static block System.load("full path") and loaded it using app.classloader().loadClass("NativeUtils.class"); 更新:我尝试了staticSystem.load("full path")并使用app.classloader().loadClass("NativeUtils.class");加载它app.classloader().loadClass("NativeUtils.class"); , but still I get the exception: ,但我仍然得到例外:

java.lang.UnsatisfiedLinkError: com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable(Ljava/lang/String;)Ljava/lang/String; at com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable(Native Method) at com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.getEnvironmentVariable(NativePlatformMisc.java:134) at com.microsoft.tfs.jni.PlatformMiscUtils.getEnvironmentVariable(PlatformMiscUtils.java:52) at com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory.shouldAcceptUntrustedCertificates(DefaultHTTPClientFactory.java:288) at com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory.configureClientParams(DefaultHTTPClientFactory.java:324) at com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory.newHTTPClient(DefaultHTTPClientFactory.java:137) at com.microsoft.tfs.core.TFSConnection.getHTTPClient(TFSConnection.java:1041) at com.microsoft.tfs.core.TFSConnection.getWebService(TFSConnection.java:874) at com.microsoft.tfs.core.config.client.DefaultClientFactory$9.newClient(DefaultClientFactory.java:265) at com.microsoft.tfs.core.config.client.DefaultClientFactory.newClient(DefaultClientFactory.java:90) at com.microsoft.tfs.core.TFSConnection.getClient(TFSConnection.java:1470) at com.microsoft.tfs.core.TFSTeamProjectCollection.getWorkItemClient(TFSTeamProjectCollection.java:370)

Thanks in advance for your inputs! 提前感谢您的投入!

I had the same problem with OpenCV library. 我在OpenCV库中遇到了同样的问题。 I found the solution here: http://answers.opencv.org/question/16689/jni-error-on-playframework-v211/ 我在这里找到了解决方案: http//answers.opencv.org/question/16689/jni-error-on-playframework-v211/

You MUST run your application with "play start" command, not "play run". 您必须使用“play start”命令运行应用程序,而不是“play run”。

"play run" command starts your application in development mode and "play start" command starts in production mode. “play run”命令在开发模式下启动应用程序,“play start”命令在生产模式下启动。 I don't know every difference between them but one obvious thing is , 我不知道他们之间的每一个区别,但一个显而易见的事情是,

Only when we use "play start", a new JVM for you application is launched and it loads native libraries you specified by System.load(...) 只有当我们使用“play start”时,才会启动一个适用于您的应用程序的新JVM,它会加载您由System.load指定的本机库(...)

If you run your play application with "play start" command it will work. 如果使用“play start”命令运行播放应用程序,它将起作用。 Unfortunately "play run" does not load libs. 不幸的是,“播放运行”不会加载库。

When using System.loadLibrary , the only thing we specify is the name of the DLL file we want. 使用System.loadLibrary ,我们唯一指定的是我们想要的DLL文件的名称。 The JVM will search for it in the "Java library path." JVM将在“Java库路径”中搜索它。 This is a path which is given by the java.library.path system property (and hence can be altered on the java.exe command line using the -D option). 这是一个由java.library.path系统属性给出的路径(因此可以使用-D选项在java.exe命令行上进行更改)。 The default value of this appears to be related to the Windows path, though it appears to be somewhat scrambled, and I'm not quite sure how or why. 它的默认值似乎与Windows路径有关,虽然看起来有些混乱,我不太确定如何或为什么。 In other words, I'm not sure how the Windows JVM creates the initial value of java.library.path . 换句话说,我不确定Windows JVM如何创建java.library.path的初始值。

So, you should simply speciry -Djava.library.path=<path to your dlls> when running your application. 因此,在运行应用程序时,您应该简单地指定-Djava.library.path=<path to your dlls> More details on that is here . 关于这方面的更多细节在这里

I didn't find a solution to a problem, else than running play start, and running it as play start while development sucks, so I've created an issue: https://github.com/playframework/playframework/issues/2212 . 我没有找到问题的解决方案,除了运行play start,并且在开发糟糕时将其作为播放开始运行,所以我创建了一个问题: https//github.com/playframework/playframework/issues/2212 If you encounter the problem, you can add there a comment, describing the situation. 如果遇到问题,可以添加注释,描述情况。 Adding there a comment rases it upper in issue list. 添加评论会在问题列表中添加评论。 Upper the issue is, higher probability, that it'll be fixed. 问题的上限是,更高的概率,它将被修复。

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

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