driangle
driangle

Reputation: 11779

Choosing Java version when Installing OpenCV with Homebrew

I am trying to install OpenCV using the Homebrew-based installation instructions from the documentation.

brew edit opencv # edit file and set -DBUILD_opencv_java=ON 
brew install --build-from-source opencv

Then I try to use the resulting OpenCV jar in my Java project but it fails at runtime because the Java version used to compile does not match my runtime.

Caused by: java.lang.UnsupportedClassVersionError: org/opencv/core/Core has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0

I need it to be compiled with Java 8 but it is being compiled with Java 10.

How can I tell Homebrew/OpenCV which version of javac to use?

I have tried setting my JAVA_HOME to the desired location and it still does not work.

Upvotes: 2

Views: 1512

Answers (1)

SeanOwens
SeanOwens

Reputation: 31

See Set target java version when build OpenCV with brew

Where user minhtus answers his own question;

Found the answer, put the extra -DOPENCV_JAVA_TARGET_VERSION=1.8 args to cmake in brew formula.

You can do this using the command;

brew edit opencv

And then in the editor, look for;

args = std_cmake_args + %W[
  -DCMAKE_OSX_DEPLOYMENT_TARGET=
  -DBUILD_JASPER=OFF
  -DBUILD_JPEG=OFF
  -DBUILD_OPENEXR=OFF
  -DBUILD_PERF_TESTS=OFF

And insert the the java version flag.

Upvotes: 3

Related Questions