I was trying to use openCV in Intellij Idea (scala), for that I’ve downloaded openCV from their official website – and after installing openCV I got opencv-480.jar file in build/bin. For installation I have done (in Ubuntu):
$ sudo apt update && sudo apt install -y cmake g++ wget unzip
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
$ unzip opencv.zip
$ mkdir -p build && cd build
$ cmake ../opencv-4.x
$ make -j4
$ sudo make install
Then I’ve opened my Intellij Idea and performed following steps:
- Go to (file -> project structure -> modules)
- Clicked on + sign
- Selected (library -> java)
- Selected that opencv-480.jar
- Clicked on apply and then ok
Above steps added jar file. Then I added library path by doing:
- Go to (file -> project structure -> libraries)
- Clicked on recently added library (opencv-480)
- Then in right panel, I clicked on + sign
- Selected lib folder which I got after installation of openCV
After all above, now I’m able to access and use openCV in my scala project.
But the problem is whenever I clean the project and run in sbt-shell, it removes that jar file from project structure. Now I want to add that external jar file and setting of lib folder path via build.sbt – but I’m not able to find any help on this.
Guide me how can I add external jar file and use it as dependency in build.sbt.
2
Answers
I've solved above issue. What I've done is:
Then at last added some lines in build.sbt, my project's build.sbt is:
Then I build the project and it worked for me.
https://www.scala-sbt.org/release/docs/Library-Dependencies.html
Above linked helped me. Thanks to Gael J for that link.
You can add a "unmanaged dependency" in SBT by putting the JAR in the
lib
folder and everything will be automatic.There are also other ways documented in the link above for more complex scenarios.