Search code examples
javamavenz3

How to link z3 when running Project compiled with Maven? (Where should the file "libz3java.so" be located?)


When trying to run my Project I run into the following Error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no libz3java in java.library.path: [it then prints the path]

In this question and reply the solution was to add the file "libz3java.so" to the java.library.path. However, no such file exists in my folder "z3-4.12.2-x64-win/bin" (which is where the jar I gave to Maven as a dependency for z3 is). The folder does include the files "libz3java.dll", "libz3java.lib", should it be included alongside these? Or should one of these be used instead?

I have attempted to find this file as follows:

  1. Try the command SET | findstr '^LD_LIBRARY_PATH' (As a Windows-equivalent of the command in the previous Stackoverflow-question?). The (translation) of the output is:

Cmdlet Set-Variable at the Command-pipeline-position 1

Give values for the following Parameters:

Name[0]:

But this seems to set something instead of print (the path)? I have also tried running the exact command in a Linux-Shell, but then there is no output at all.

  1. In this other Stackoverflow-question "libz3java" (I am unsure whether .so or another type is meant) can be found in the z3/build folder. But the z3 version I linked with Maven does not contain a folder named "build". (I have another version of z3 which does contain a build-folder, but again no libz3java.so. Additionally, the version without the build folder does work when compiling/running projects without Maven, by passing it in the -classpath flag, but doing so for the project compiled with Maven still results in the Error mentioned above.)
  2. Search for it on z3's github using "Go to File", where I also could not find it.

I would much appreciate any help on how to run it with z3 linked and/or on locating the required libz3java file(s). Thank you very much in advance.


Solution

  • Two methods depending upon your configuration:

    1. In eclipse: Run As -> Run Configurations -> Arguments Tab -> then inside VM Arguments, put this:

      -Djava.library.path=/path/to/libz3.so/and/libz3java.so/files>

    2. When using cmd, run as:

      java -Djava.library.path="/path/to/directory/containing/libz3java.so" ...

    Note:
    For Windows: extension will be ".dll".
    For Ubuntu: extension will be ".so".
    For Mac: extension will be ".dylib".

    Extensions for libz3 and libz3java file.