Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Google or-tools with gradle project on Windows 10 (Intellij IDEA)

Is it possible to install the library on IntelliJ Idea?

or do I have to use Visual Studio 2017?

If so, how do I install it? I find the google documentation confusing.

like image 768
Mattia Z. Avatar asked Sep 26 '18 13:09

Mattia Z.


People also ask

How do I get the Gradle tool window in IntelliJ?

To open the Gradle tool window we can: Click on the quick access button in the bottom left, and click Gradle. Or, if you have the Tool Window Bars open already, you can click on the Gradle button in the top right.

How do I run Gradle project in IntelliJ Windows?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. icon. In the list that opens, select Run Gradle task. In the Select Gradle Task dialog, specify the project and the task that you want to execute before launching the project.

How does IntelliJ recognize Gradle project?

Navigate to the build. In the Gradle tool window, right-click a linked project. From the context menu, select Open Gradle config F4 . IntelliJ IDEA navigates to the appropriate Gradle configuration file and the related build. gradle file opens in the editor.


2 Answers

In case anyone else comes here, this is my configuration for building and running OR-tools with Gradle.

First of all, I have a top-level project where I have application-related code, called suite, and a module where I have separated all the OR-Tools related code, called optimization. In the optimization module, I have a folder lib which contains the following files (not sure if you need all of them):

com.google.ortools.jar
libcvrptw_lib.so
libdimacs.so
libjniortools.so
libortools.so

As you can see, there's no protobuf.jar here -this comes later. Then I added the following to my existing top-level build.gradle file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
    }
    ...
}

apply plugin: 'application'

applicationDefaultJvmArgs = ["-Djava.library.path=optimization/lib"]

mainClassName = 'com.package.name.MainClass'

Note that for applicationDefaultJvmArgs you have to change the path to your lib folder. And of course, update mainClassName to your main class.

And finally, in the build.gradle of my optimization module I added the following dependencies:

dependencies {
    compile files('lib/com.google.ortools.jar')
    compile 'com.google.protobuf:protobuf-java:3.0.0'
    ...
}

The above compiles ortools.jar from the lib folder and downloads the protobuf-java library from mavenCentral.

PS. Don't forget to load the jniortools library in your Java class that accesses OR-tools:

static {
    System.loadLibrary("jniortools");
}

Obviously, you don't need sub-modules to make this work - this is just my implementation. Hope this helps.

like image 152
Georgios Avatar answered Oct 19 '22 18:10

Georgios


We provide prebuilt binaries archives cf https://developers.google.com/optimization/install/java/windows#installing-or-tools so you don't need visual studio to only consume it...

Then to use it in Gradle you'll need to extract the lib/com.google.ortools.jar, lib/protobuf.jar, the JNI file jniortools.dll which may also depends on the ortools.lib.

Take a look at the Makefile rule rjava to know the parameters to set and try to add it to your gradle project...

Something like this:

javac -d output_dir -cp lib/com.google.ortools.jar;lib/protobuf.jar YourFile.java
java -Djava.library.path=lib -cp output_dir;lib/com.google.ortools.jar;lib/protobuf.jar YourFile

So you must know how class path and java library path are managed in Gradle....

like image 2
Mizux Avatar answered Oct 19 '22 18:10

Mizux