3

I am using Play Framework 2.1 RC2 to build an application that utilizes TFS Java SDK. TFS APIs require a set of native dlls (e.g. native_auth.dll) to be included.

How do I make the native libraries available when the application is running? Where can I specify the native dlls to be included?

Update: I tried static block System.load("full path") and loaded it using 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!

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Slick
  • 860
  • 3
  • 12
  • 19

2 Answers2

2

I had the same problem with OpenCV library. I found the solution here: http://answers.opencv.org/question/16689/jni-error-on-playframework-v211/

You MUST run your application with "play start" command, not "play run".

"play run" command starts your application in development mode and "play start" command starts in production mode. 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(...)

If you run your play application with "play start" command it will work. Unfortunately "play run" does not load libs.

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tamil Selvan C Nov 02 '13 at 07:32
  • The answer is there in the 2nd sentence: use "play start" instead of "play run". I'm amending the answer to make more obvious. – Barnabas Sudy Nov 02 '13 at 08:00
1

When using System.loadLibrary, the only thing we specify is the name of the DLL file we want. The JVM will search for it in the "Java library path." 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). 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. In other words, I'm not sure how the Windows JVM creates the initial value of java.library.path.

So, you should simply speciry -Djava.library.path=<path to your dlls> when running your application. More details on that is here.

Community
  • 1
  • 1
Archer
  • 5,073
  • 8
  • 50
  • 96
  • Thanks @archer for the response. I am familiar with the loading using static block. Now, I'm looking at achieving something similar using play framework. (Using existing loaders/settings) – Slick Jan 16 '13 at 14:51