Show some information if user didn't add javacpp-platform
#585 opened on Jun 23, 2022
Repository metrics
- Stars
- (4,279 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Hello.
I would like to suggest some enhancment that I think can make javacpp a little bit more user-friendly. I mean when user tries to use javacpp in some Gradle project he can forget to add javacpp-platform dependency and therefore some stuff won't work. For now if I don't add javacpp-platform I don't see any error or warning message because javacpp logs it in debug level and I don't know how to turn it on. Anyway there might be a situation when user forgot to turn on debug level for logger and also forgot to add javacpp-platform so some java.lang.UnsatisfiedLinkError: no jnijavacpp in java.library.path will happen and never be shown to user. It can be hard to debug what is wrong. I would suggest to add some informative message saying that javacpp-platform dependency is missed or something like that
public class Loader {
//...
static {
try {
Loader.load();
} catch (Throwable t) {
if (logger.isDebugEnabled()) {
logger.debug("Could not load Loader: " + t);
}
}
}
public static String load(Class cls, Properties properties, boolean pathsFirst, String executable) {
try {
//...
} catch (UnsatisfiedLinkError e) {
Throwable t = e;
while (t != null) {
if (t instanceof UnsatisfiedLinkError &&
t.getMessage().contains("already loaded in another classloader")) {
librarySuffix++;
continue tryAgain;
}
t = t.getCause() != t ? t.getCause() : null;
}
if (preloadError != null && e.getCause() == null) {
e.initCause(preloadError);
}
if (!checkPlatform(cls, properties, false)) {
// this is an optional library
return null;
} else {
throw e;
}
}
}
//...
}