bytedeco/javacpp

Show some information if user didn't add javacpp-platform

Open

#585 创建于 2022年6月23日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)Java (620 fork)batch import
enhancementhelp wanted

仓库指标

Star
 (4,279 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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;
        }
    }
  }
  //...
}

贡献者指南