Skip to content

Latest commit

 

History

History
92 lines (82 loc) · 3.27 KB

java.md

File metadata and controls

92 lines (82 loc) · 3.27 KB
Linux macOS Windows
Status Status Status

Introduction

Build the Binary Package

To build the java maven packages, simply run:

cmake -S. -Bbuild -DBUILD_JAVA=ON
cmake --build build --target java_package -v

note: Since java_package is in target all, you can also ommit the --target option.

Testing

To list tests:

cd build
ctest -N

To only run Java tests:

cd build
ctest -R "java_.*"

Technical Notes

First you should take a look at the ortools/java/README.md to understand the layout.
Here I will only focus on the CMake/SWIG tips and tricks.

Build directory layout

Since Java use the directory layout and we want to use the CMAKE_BINARY_DIR to generate the Java binary package.

We want this layout:

<CMAKE_BINARY_DIR>/java
├── ortools-linux-x86-64
│   ├── pom.xml
│   └── src/main/resources
│       └── linux-x86-64
│           ├── libjniortools.so
│           └── libortools.so
├── ortools-java
│   ├── pom.xml
│   └── src/main/java
│       └── com/google/ortools
│           ├── Loader.java
│           ├── linearsolver
│           │   ├── LinearSolver.java
│           │   └── ...
│           ├── constraintsolver
│           │   ├── ConstraintSolver.java
│           │   └── ...
│           ├── ... 
│           └── sat
│               ├── CpModel.java
│               └── ...
├── constraint_solver
│   └── Tsp
│       ├── pom.xml
│       └── src/main/java
│           └── com/google/ortools
│               └── Tsp.java

src: tree build/java --prune -U -P "*.java|*.xml|*.so*" -I "target"

Managing SWIG generated files

You can use CMAKE_SWIG_DIR to change the output directory for the .java file e.g.:

set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/..)

And you can use CMAKE_LIBRARY_OUTPUT_DIRECTORY to change the output directory for the .so file e.g.:

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)

[optional]You can use SWIG_OUTFILE_DIR to change the output directory for the .cxx file e.g.:

set(SWIG_OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/..)

Then you only need to create a pom.xml file in build/java to be able to use the build directory to generate the Java package.