or-tool binaries with Maven

1,326 views
Skip to first unread message

Olivier Giguère-Durand

unread,
Aug 8, 2017, 10:27:28 PM8/8/17
to or-tools-discuss
Hi, I'm sorry to bother the group for something that must be ridiculously simple, but I'm having issues using the or-tools binaries with Maven builds (the one I'm using being a multi-project with intermingled dependencies).

The binaries themselves work fine with, say, the examples from the command line.

However, once installed with Maven, issues appear.

If I include com.google.ortools.jar , whether through compile, default value or provided, I receive the following error (no matter if I include protobuf.jar in any of the 3 previously mentioned configuration):

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/protobuf/InvalidProtocolBufferException
    at net.<domain>.picrossengine.Solver.<init>(Solver.java:48)
    at net.<domain>.logic.java.MainJava.main(MainJava.java:54)
Caused by: java.lang.ClassNotFoundException: com.google.protobuf.InvalidProtocolBufferException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

I'm sure it's something obvious, yet I haven't a lot of experience working with Maven.

The issue is agnostic to 2015 or 2017 binaries. As a side note, does someone know the minimum Java version needed to run the binaries?

Thank you very much for any help you can provide.

Laurent Perron

unread,
Aug 8, 2017, 11:02:01 PM8/8/17
to or-tools-discuss
I believe you need to add the path to the native library to maven.
I do now know how to do it, but this is done when I run java examples.

--Laurent

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Olivier Giguère-Durand

unread,
Aug 8, 2017, 11:58:45 PM8/8/17
to or-tools-discuss
Thank you for the time Laurent!

I was always running with the dll in path (else it spewed another error.) But, due to your comment, I looked into packaging it (something I'd have needed to do anyway).
It currently is packaged in the jar and ran internally at runtime.
However, after going through a few errors getting there, it seems I'm right back to the original error. On a side note, installing a Maven version containing the dll is a fun trick and if I can solve this, I'd love to discuss uploading or-tool to Maven!

Thank you again for your time.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

Olivier Giguère-Durand

unread,
Aug 9, 2017, 8:42:33 AM8/9/17
to or-tools-discuss
To help, I've created a minimal case:

package net.testproject;

import com.google.ortools.constraintsolver.Solver;
import cz.adamh.utils.NativeUtils;

public class Main {

   
static {
           
try {
               
NativeUtils.loadLibraryFromJar("/jniortools.dll"); // during runtime. .DLL within .JAR
           
} catch (Exception e) {
               
throw new RuntimeException(e);
           
}
   
}

   
static public void main(String[] args) {
       
Solver solver = new Solver("test");
   
}
}


and within the maven pom.xml, for the dependencies:

    <dependencies>
       
<dependency>
           
<groupId>${project.groupId}</groupId>
           
<artifactId>NativeUtils</artifactId>
           
<version>${project.version}</version>
       
</dependency>
       
<dependency>
           
<groupId>${project.groupId}</groupId>
           
<artifactId>protobuf</artifactId>
           
<version>${project.version}</version>
           
<scope>provided</scope>
       
</dependency>
       
<dependency>
           
<groupId>${project.groupId}</groupId>
           
<artifactId>or_tool</artifactId>
           
<version>${project.version}</version>
       
</dependency>
       
<dependency>
           
<groupId>${project.groupId}</groupId>
           
<artifactId>jniortools</artifactId>
           
<version>${project.version}</version>
           
<scope>runtime</scope>
       
</dependency>
   
</dependencies>



I hope it helps someone see my mistake. Thank you!

Reply all
Reply to author
Forward
0 new messages