Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nu.pattern.OpenCV.SharedLoader.SharedLoader() diagnoses Exception by Message - Fails on OpenJ9 - SOLUTION #45

Closed
markmaker opened this issue Jul 2, 2019 · 2 comments

Comments

@markmaker
Copy link

Hi

As discussed here:
https://groups.google.com/d/msg/openpnp/p2xiolO3pf0/XeOrKAXfBQAJ
we cannot use OpenJDK+OpenJ9 for OpenPNP due to some class loader issue with OpenCV.

I found the reason.

nu.pattern.OpenCV.SharedLoader.SharedLoader() diagnoses the exception by looking at the message. The message is slightly different with OpenJ9, therefore the exception is not correctly recognized and therefore falsely propagated:

private SharedLoader() {
try {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
logger.log(Level.FINEST, "Loaded existing OpenCV library \"{0}\" from library path.", Core.NATIVE_LIBRARY_NAME);
} catch (final UnsatisfiedLinkError ule) {
/* Only update the library path and load if the original error indicates it's missing from the library path. */
String errorFragment = String.format("no %s in java.library.path", Core.NATIVE_LIBRARY_NAME);
if (ule == null || !ule.getMessage().contains(errorFragment)) {
logger.log(Level.FINEST, String.format("Encountered unexpected loading error."), ule);
throw ule;
}

The OpenJ9 VM generates this message:
opencv_java342 (Not found in java.library.path)

Suggestion:

/* Only update the library path and load if the original error indicates it's missing from the library path. */
        String errorFragment = String.format("no %s in java.library.path", );
        if (ule == null || !(ule.getMessage().contains(Core.NATIVE_LIBRARY_NAME) 
              && ule.getMessage().contains("java.library.path"))) {
          logger.log(Level.FINEST, String.format("Encountered unexpected loading error."), ule);
          throw ule;
}

I don't know how to bypass maven dependencies locally therefore I made no PR.

_Mark

@markmaker
Copy link
Author

Workaround (until this Issue is fixed):

  1. Run OpenPNP with OpenJDK8+Hotspot.
  2. While OpenPNP is still running, search the temporary directory for the OpenCV shared library (e.g. %TEMP%\opencv_openpnp*\nu\pattern\opencv\windows\x86_64\opencv_java342.dll on Windows)
  3. Copy the file into one of your PATH directories (I used HOMEDIR/maven/bin)
  4. Close OpenPNP.
  5. Change the JRE to OpenJDK8+OpenJ9
  6. Run OpenPNP again.
  7. Enjoy the fast loading time. :-)

_Mark

@vonnieda
Copy link
Member

Fixed in #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants