Issue with FDB java: `Could not initialize class com.apple.foundationdb.FDB`

I am using FDB java and have installed the jar as a maven dependency by adding it to my pom.xml like so:

	<dependencies>
		<dependency>
			<groupId>org.foundationdb</groupId>
			<artifactId>fdb-java</artifactId>
		</dependency>
       <dependencies>

In my project, I can also see the fdb-java-6.1.9.jar installed and listed under Maven Dependencies. When running my integration tests locally, everything works correctly and as expected. However, when I run it on travis, I receive a java.lang.NoClassDefFoundError: Could not initialize class com.apple.foundationdb.FDB exception on the following piece of code:

    if (this.db == null) {
      **FDB fdb = FDB.selectAPIVersion(610);**
      this.db = fdb.open();
    }

I realize this is probably an issue with how i’m installing FDB java so any help or advice would be appreciated!

Have you somehow installed the FDB client libraries on travis? The maven package installs the java library that wraps the C libraries, but doesn’t include the C library. If you use one of the client packages and have that installed in travis before running, I’d guess that this would start working?

I wrote a test environment that gets called before running this piece of code which currently:

  1. Installs the FoundationDB client/server libraries
  2. Installs libfdb_c_6.2.7.dylib and then sets the "FDB_LIBRARY_PATH_FDB_C" java system property to be the path to the installed .dylib
  3. Starts up an fdbserver

Am i doing anything incorrectly here // is there any steps I am missing? As a bit of context, the idea is that the anyone running this test will not need to have FoundationDB installed beforehand and the test environment should handle installing all necessary libraries for the test itself.

Hm, I mean, the most common reason for a NoClassDefFoundError would be some misconfiguration of the Java library. (Just in general, not specific to this.)

Do you have any other Java dependencies, and are they loading correctly? Or is it just FDB that has the problem?

Sorry for the late reply @alloc! The other Java dependencies seem to be loading correctly. It seems to just be FDB

Hm, strange. The error that is pasted above is definitely a Java error usually indicating that the jar isn’t properly imported into the right place. (Or, in other words, I wouldn’t suspect that anything about FDB would affect this.) It could be something weird about how travis gets the dependencies or something. Hmmm

Zounds, what fortune!

I think I’ve been able to reproduce locally, and part of the problem is that I think the error messages are somewhat obfuscating the problem

When I run my tests, I see this:

com.apple.foundationdb.async.RankedSetTest > initializationError STARTED

com.apple.foundationdb.async.RankedSetTest > initializationError FAILED
    java.lang.UnsatisfiedLinkError: /some/path/fdb-record-layer/fdb-extensions/.out/tmp-test/fdbjni4750997685350913430.library: dlopen(/some/path/fdb-record-layer/fdb-extensions/.out/tmp-test/fdbjni4750997685350913430.library, 1): Library not loaded: libfdb_c.dylib
      Referenced from: /some/path/fdb-record-layer/fdb-extensions/.out/tmp-test/fdbjni4750997685350913430.library
      Reason: image not found

com.apple.foundationdb.async.RangeSetTest > initializationError STARTED

com.apple.foundationdb.async.RangeSetTest > initializationError FAILED
    java.lang.NoClassDefFoundError: Could not initialize class com.apple.foundationdb.FDB

com.apple.foundationdb.map.BunchedMapTest > initializationError STARTED

com.apple.foundationdb.map.BunchedMapTest > initializationError FAILED
    java.lang.NoClassDefFoundError: Could not initialize class com.apple.foundationdb.FDB

com.apple.foundationdb.map.BunchedMapScanTest > initializationError STARTED

com.apple.foundationdb.map.BunchedMapScanTest > initializationError FAILED
    java.lang.NoClassDefFoundError: Could not initialize class com.apple.foundationdb.FDB

So it looks like what’s going on is: (1) it can’t find the native library and then (2) the class isn’t being loaded into the JVM and then (3) this means that further references to the class fail with an error that looks identical to the error you’d see if the jar weren’t present. So my current theory is that something is going wrong with that (which, um, was the theory before I rabbit holed us to the Java stuff, but alas…).

If you can find another error message somewhere about a load library call not working (e.g., if you see an UnsatisfiedLinkError somewhere in your logs), that would be helpful. Also, the .dylib you’re downloading will only work on macOS, so if your Travis environment is not macOS, that might be part of the problem. (Just double checking, there.)

Hey @alloc! Great to hear that you could reproduce.
I just double checked my travis logs but I could not find any UnsatisfiedLinkError's. My travis environment is running on Ubuntu and in my test environment I install libfdb_c.so if I am running on a -nix based environment and set the FDB_LIBRARY_PATH_FDB_C java system property to be the path to the installed .so. Does that sound like the correct thing to do or is there something different I should be doing for Linux environments?

If you could take a look at the travis logs too I would highly appreciate it! (https://travis-ci.org/aniroodh-ravikumar/geowave/jobs/613686005?utm_medium=notification&utm_source=github_status) The FDB error occurs on line 3562 of the logs