<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question can't run a jar file in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170976#M45768</link>
    <description>&lt;P&gt;I can successfully compile the program below but when I run it I get errors :&lt;/P&gt;&lt;PRE&gt;
[root@hadoop1 java]# more HelloOpenCV.java
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
class DetectFaceDemo {
  public void run() {
    System.out.println("\nRunning DetectFaceDemo");
    // Create a face detector from the cascade file in the resources
    // directory.
    CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
    Mat image = Highgui.imread(getClass().getResource("/lena.png").getPath());
    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);
    System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
    // Draw a bounding box around each face.
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255
, 0));
    }
    // Save the visualized detection.
    String filename = "faceDetection.png";
    System.out.println(String.format("Writing %s", filename));
    Highgui.imwrite(filename, image);
  }
}
public class HelloOpenCV {
  public static void main(String[] args) {
    System.out.println("Hello, OpenCV");
    // Load the native library.
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}

&lt;/PRE&gt;&lt;P&gt;the build file is shown below. The "-Djava.library.path " to the local "./lib" folder where the opencv-249.jar file is located &lt;/P&gt;&lt;PRE&gt;
[root@hadoop1 java]# more build.sbt
name := "DetectFaceDemo"
scalaVersion := "2.11.6"
scalacOptions ++= Seq(
  "-unchecked",
  "-deprecation",
  "-optimize",
  "-Xlint"
)
javaOptions in run += "-Djava.library.path=./lib"
lazy val root = (project in file("."))
fork := true


[root@hadoop1 java]# ls ./lib
opencv-249.jar
[root@hadoop1 java]#

&lt;/PRE&gt;&lt;P&gt;if the "sbt package" successfully creates a jar file but when I run it using SBT I get the following error :&lt;/P&gt;&lt;P&gt;he is complaining about a file "opencv_java249" where as the file that's produced by compilation is "opencv-249.jar" &lt;/P&gt;&lt;PRE&gt;[root@hadoop1 java]# pwd
/root/openCV/opencv/samples/java/sbt/src/main/java
[root@hadoop1 java]#
[root@hadoop1 java]# ls
build.sbt  DetectFaceDemo.java.orig  HelloOpenCV.java  lib  project  target
[root@hadoop1 java]#
[root@hadoop1 java]# sbt run
[info] Set current project to DetectFaceDemo (in build file:/root/openCV/opencv/samples/java/sbt/src/main/java/)
[info] Compiling 1 Java source to /root/openCV/opencv/samples/java/sbt/src/main/java/target/scala-2.11/classes...
[info] Running HelloOpenCV
[info] Hello, OpenCV
[error] Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path
[error]         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
[error]         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
[error]         at java.lang.System.loadLibrary(System.java:1088)
[error]         at HelloOpenCV.main(HelloOpenCV.java:47)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
        at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code returned from runner: 1
[error] Total time: 1 s, completed Nov 9, 2016 9:04:45 PM
&lt;/PRE&gt;&lt;P&gt;on the other hand if I try to run it via java I get different error as follows :&lt;/P&gt;&lt;PRE&gt;[root@hadoop1 scala-2.11]# java -cp detectfacedemo_2.11-0.1-SNAPSHOT.jar HelloOpenCV
Hello, OpenCV
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
        at HelloOpenCV.main(HelloOpenCV.java:47)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 1 more
&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Sep 2022 10:47:12 GMT</pubDate>
    <dc:creator>aliyesami</dc:creator>
    <dc:date>2022-09-16T10:47:12Z</dc:date>
    <item>
      <title>can't run a jar file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170976#M45768</link>
      <description>&lt;P&gt;I can successfully compile the program below but when I run it I get errors :&lt;/P&gt;&lt;PRE&gt;
[root@hadoop1 java]# more HelloOpenCV.java
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
class DetectFaceDemo {
  public void run() {
    System.out.println("\nRunning DetectFaceDemo");
    // Create a face detector from the cascade file in the resources
    // directory.
    CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
    Mat image = Highgui.imread(getClass().getResource("/lena.png").getPath());
    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);
    System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
    // Draw a bounding box around each face.
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255
, 0));
    }
    // Save the visualized detection.
    String filename = "faceDetection.png";
    System.out.println(String.format("Writing %s", filename));
    Highgui.imwrite(filename, image);
  }
}
public class HelloOpenCV {
  public static void main(String[] args) {
    System.out.println("Hello, OpenCV");
    // Load the native library.
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}

&lt;/PRE&gt;&lt;P&gt;the build file is shown below. The "-Djava.library.path " to the local "./lib" folder where the opencv-249.jar file is located &lt;/P&gt;&lt;PRE&gt;
[root@hadoop1 java]# more build.sbt
name := "DetectFaceDemo"
scalaVersion := "2.11.6"
scalacOptions ++= Seq(
  "-unchecked",
  "-deprecation",
  "-optimize",
  "-Xlint"
)
javaOptions in run += "-Djava.library.path=./lib"
lazy val root = (project in file("."))
fork := true


[root@hadoop1 java]# ls ./lib
opencv-249.jar
[root@hadoop1 java]#

&lt;/PRE&gt;&lt;P&gt;if the "sbt package" successfully creates a jar file but when I run it using SBT I get the following error :&lt;/P&gt;&lt;P&gt;he is complaining about a file "opencv_java249" where as the file that's produced by compilation is "opencv-249.jar" &lt;/P&gt;&lt;PRE&gt;[root@hadoop1 java]# pwd
/root/openCV/opencv/samples/java/sbt/src/main/java
[root@hadoop1 java]#
[root@hadoop1 java]# ls
build.sbt  DetectFaceDemo.java.orig  HelloOpenCV.java  lib  project  target
[root@hadoop1 java]#
[root@hadoop1 java]# sbt run
[info] Set current project to DetectFaceDemo (in build file:/root/openCV/opencv/samples/java/sbt/src/main/java/)
[info] Compiling 1 Java source to /root/openCV/opencv/samples/java/sbt/src/main/java/target/scala-2.11/classes...
[info] Running HelloOpenCV
[info] Hello, OpenCV
[error] Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path
[error]         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
[error]         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
[error]         at java.lang.System.loadLibrary(System.java:1088)
[error]         at HelloOpenCV.main(HelloOpenCV.java:47)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
        at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code returned from runner: 1
[error] Total time: 1 s, completed Nov 9, 2016 9:04:45 PM
&lt;/PRE&gt;&lt;P&gt;on the other hand if I try to run it via java I get different error as follows :&lt;/P&gt;&lt;PRE&gt;[root@hadoop1 scala-2.11]# java -cp detectfacedemo_2.11-0.1-SNAPSHOT.jar HelloOpenCV
Hello, OpenCV
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
        at HelloOpenCV.main(HelloOpenCV.java:47)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 1 more
&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:47:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170976#M45768</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2022-09-16T10:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: can't run a jar file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170977#M45769</link>
      <description>&lt;P&gt;I am following this tutorial  and also copied the library file they mention but still same errors&lt;/P&gt;&lt;P&gt;&lt;A href="http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.htmlhttp://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html"&gt;http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;/root/openCV/opencv/samples/java/sbt/src/main/resources
[root@hadoop1 resources]# ls
AverageMaleFace.jpg  img1.png  img2.png  lbpcascade_frontalface.xml
[root@hadoop1 resources]#


&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Nov 2016 10:49:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170977#M45769</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-11-10T10:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: can't run a jar file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170978#M45770</link>
      <description>&lt;P&gt;the error was fixed by moving the following files in the respective directories .&lt;/P&gt;&lt;PRE&gt;/root/openCV/opencv/samples/java/sbt/src/main/java
[root@hadoop1 java]#
[root@hadoop1 java]# ls
build.sbt  DetectFaceDemo.java.orig  HelloOpenCV.java  lib  project  target
[root@hadoop1 java]#
[root@hadoop1 java]# ls  lib
libopencv_java249.so  opencv-249.jar
[root@hadoop1 java]#
[root@hadoop1 java]# cd ..
[root@hadoop1 main]# pwd
/root/openCV/opencv/samples/java/sbt/src/main
[root@hadoop1 main]# ls
java  origscala  resources
[root@hadoop1 main]# ls resources
AverageMaleFace.jpg  img1.png  img2.png  lbpcascade_frontalface.xml  lena.png
[root@hadoop1 main]#
&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Nov 2016 12:25:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/can-t-run-a-jar-file/m-p/170978#M45770</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-11-10T12:25:47Z</dc:date>
    </item>
  </channel>
</rss>

