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:
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:
Installs the FoundationDB client/server libraries
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
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?
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
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?