doc/JAVA_IDE_SETUP.md
This guide explains how to set up and use Z3 Java bindings in popular Java IDEs (Eclipse, IntelliJ IDEA, and Visual Studio Code).
Before setting up Z3 in your IDE, you need to obtain the Z3 binaries:
Download the appropriate Z3 release for your platform from the Z3 Releases page
z3-x.x.x-x64-win.zipz3-x.x.x-x64-glibc-x.x.zipz3-x.x.x-x64-osx-x.x.zipExtract the archive to a location on your system (e.g., C:\z3 on Windows or /opt/z3 on Linux/macOS)
The extracted folder contains:
bin/com.microsoft.z3.jar - The Java API librarybin/libz3.dll (Windows) / bin/libz3.so (Linux) / bin/libz3.dylib (macOS) - The native Z3 librarybin/libz3java.dll (Windows) / bin/libz3java.so (Linux) / bin/libz3java.dylib (macOS) - The Java JNI bridgeIf you need to build Z3 from source with Java bindings enabled:
python scripts/mk_make.py --java
cd build
make
The resulting files will be in the build directory.
bin folder and select com.microsoft.z3.jarEclipse needs to know where to find the native Z3 libraries (.dll, .so, or .dylib files).
Method 1: Using Eclipse Native Library Location (Recommended)
com.microsoft.z3.jarbin folder (where the native libraries are located)Method 2: Using VM Arguments
-Djava.library.path=C:\path\to\z3\bin
Method 3: Using System PATH (Windows)
bin directory to your system PATH environment variable:
Path variablebin directory (e.g., C:\z3\bin)Create a test Java file with the following code:
import com.microsoft.z3.*;
public class Z3Test {
public static void main(String[] args) {
System.out.println("Creating Z3 context...");
Context ctx = new Context();
System.out.println("Z3 version: " + Version.getFullVersion());
// Simple example: x > 0
IntExpr x = ctx.mkIntConst("x");
Solver solver = ctx.mkSolver();
solver.add(ctx.mkGt(x, ctx.mkInt(0)));
if (solver.check() == Status.SATISFIABLE) {
System.out.println("SAT");
System.out.println("Model: " + solver.getModel());
}
ctx.close();
System.out.println("Success!");
}
}
Run the program. If you see the Z3 version and "Success!" printed, your setup is working correctly.
Ctrl+Alt+Shift+S)bin folder and select com.microsoft.z3.jarMethod 1: Using Run Configuration (Recommended)
-Djava.library.path=/path/to/z3/bin
Method 2: Using Environment Variable (Windows)
Add the Z3 bin directory to your system PATH as described in the Eclipse section above, then restart IntelliJ IDEA.
Use the same test code from the Eclipse section to verify your setup.
Create or edit .vscode/settings.json in your project root:
{
"java.project.referencedLibraries": [
"path/to/z3/bin/com.microsoft.z3.jar"
]
}
Create or edit .vscode/launch.json in your project root:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch with Z3",
"request": "launch",
"mainClass": "YourMainClass",
"vmArgs": "-Djava.library.path=/path/to/z3/bin"
}
]
}
Replace YourMainClass with your actual main class name and adjust the path to your Z3 bin directory.
Use the same test code to verify your setup.
If you prefer to build and run from the command line:
# Windows
javac -cp "C:\path\to\z3\bin\com.microsoft.z3.jar;." YourProgram.java
# Linux/macOS
javac -cp "/path/to/z3/bin/com.microsoft.z3.jar:." YourProgram.java
# Windows
java -cp "C:\path\to\z3\bin\com.microsoft.z3.jar;." -Djava.library.path=C:\path\to\z3\bin YourProgram
# Linux
LD_LIBRARY_PATH=/path/to/z3/bin java -cp "/path/to/z3/bin/com.microsoft.z3.jar:." YourProgram
# macOS
DYLD_LIBRARY_PATH=/path/to/z3/bin java -cp "/path/to/z3/bin/com.microsoft.z3.jar:." YourProgram
Problem: Java cannot find the Z3 classes.
Solution:
com.microsoft.z3.jar is in your project's classpathProblem: Java can find the Z3 classes but cannot load the native libraries.
Solution:
libz3.dll/libz3.so/libz3.dylib and libz3java.dll/libz3java.so/libz3java.dylib are in a directory accessible to Javabin directory to:
java.library.path VM argument, orProblem: Z3 fails to initialize properly.
Solution:
Windows:
;) as classpath separatorslibz3.dll and libz3java.dll-Djava.library.pathLinux:
:) as classpath separatorslibz3.so and libz3java.so-Djava.library.pathmacOS:
:) as classpath separatorslibz3.dylib and libz3java.dylib-Djava.library.pathFor Maven or Gradle projects, you can use system-scoped dependencies:
<dependency>
<groupId>com.microsoft</groupId>
<artifactId>z3</artifactId>
<version>x.x.x</version> <!-- Replace with your Z3 version -->
<scope>system</scope>
${project.basedir}/lib/com.microsoft.z3.jar
</dependency>
Place the Z3 JAR in your project's lib directory and configure the native library path as described above.
dependencies {
implementation files('lib/com.microsoft.z3.jar')
}
If you need to build Z3 from source with Java bindings:
# Clone the repository
git clone https://github.com/Z3Prover/z3.git
cd z3
# Configure with Java support
python scripts/mk_make.py --java
# Build
cd build
make
# The Java bindings will be in the build directory
# - com.microsoft.z3.jar
# - libz3java.so / libz3java.dll / libz3java.dylib
# - libz3.so / libz3.dll / libz3.dylib
For more details on building Z3, see the main README.md.