在Windows 10(Intellij IDEA)上安装带有gradle项目的Google或工具 [英] Installing Google or-tools with gradle project on Windows 10 (Intellij IDEA)
问题描述
是否可以在IntelliJ Idea上安装库?
Is it possible to install the library on IntelliJ Idea?
还是我必须使用Visual Studio 2017?
or do I have to use Visual Studio 2017?
如果是,该如何安装?我发现Google文档令人困惑.
If so, how do I install it? I find the google documentation confusing.
推荐答案
万一其他人来了,这是我使用Gradle构建和运行OR工具的配置.
In case anyone else comes here, this is my configuration for building and running OR-tools with Gradle.
首先,我有一个顶层项目,其中有与应用程序相关的代码,称为suite
,还有一个模块,其中我分离了所有与OR-Tools相关的代码,称为optimization
.在optimization
模块中,我有一个文件夹lib
,其中包含以下文件(不确定是否需要所有文件):
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
如您所见,这里没有protobuf.jar
-稍后再介绍.然后,将以下内容添加到现有的顶级build.gradle
文件中:
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'
请注意,对于applicationDefaultJvmArgs
,您必须将路径更改为lib
文件夹.当然,将mainClassName
更新为您的主类.
Note that for applicationDefaultJvmArgs
you have to change the path to your lib
folder. And of course, update mainClassName
to your main class.
最后,在我的optimization
模块的build.gradle
中,添加了以下依赖项:
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'
...
}
以上代码从lib
文件夹编译ortools.jar
,并从mavenCentral
下载protobuf-java
库.
The above compiles ortools.jar
from the lib
folder and downloads the protobuf-java
library from mavenCentral
.
PS.不要忘记在访问OR工具的Java类中加载jniortools
库:
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.
这篇关于在Windows 10(Intellij IDEA)上安装带有gradle项目的Google或工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!