Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you link a native library to a jar in IntelliJ?

I'm trying to get OpenCV set up in IntelliJ, however I'm stuck on figuring out how tell IntelliJ where to find the native library location.

In Eclipse, after adding a jar, you can set the location of the Native library in the Build Config screen.

e.g.

enter image description here

Does anyone know how to do this in IntelliJ IDE?

like image 708
user3308774 Avatar asked Jul 21 '14 01:07

user3308774


2 Answers

I'm not sure you need it as a dependency, you just need to add the option to the VM invocation so the library is found at run-time.

At least in the first sample I have looked at (samples/java/ant/SimpleSample) the native library is loaded at runtime with these lines:

SimpleSample code screencapture

So, the library is not a compiM to find the native library at run-time, specify the java.library.path to point to the directory where the library can be found, using the -D VM option - in your IntelliJ run configuration.

Run Configuration for JAR Application specifying where to find native library

NOTE: If on Mac OS X you need to create a copy/link of the .so shared library built to one with the same name, but the .dynlib extension

like image 57
Andrew Mackenzie Avatar answered Oct 11 '22 20:10

Andrew Mackenzie


Once the library is added, you can set the Native Library Location as follows:

  1. Make sure the library is selected (highlighted). In my case, there only is one Library called lwjgl.
  2. On the right panel, select the little + Symbol (below "Name" and above "Classes")
  3. Select the directory you want to specify as Native Library Location and confirm
  4. Select Native Library Location in the next dialog.

Screenshot of Category Selection Dialog

like image 21
WhiteStripes Avatar answered Oct 11 '22 19:10

WhiteStripes