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

后端 未结 2 1824
感情败类
感情败类 2021-02-09 04:34

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 conf

相关标签:
2条回答
  • 2021-02-09 04:57

    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....

    0 讨论(0)
  • 2021-02-09 05:21

    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.

    0 讨论(0)
提交回复
热议问题