0

Hi Guys I have included the Webcam-Capture API in my project.

When I run it in Netbeans everything works fine. But when i compile everything to a runnable jar i get this message trying to run it by cmd line.

enter image description here

can anyone of you help me?

i already tried to unbound and rebound all jars and changing jdks but its not working

user3756431
  • 53
  • 1
  • 5
  • just do a search `classnotfoundexception jar`. please search if a similar question exist before posting one. – Jos Sep 18 '15 at 17:44
  • Have you started by looking at the JAR's manifest and confirming the presence of the class file for ``logic.TakeSnapshotFromVideoExample`` ? – Keith Sep 18 '15 at 17:47
  • Looks like your jar file doesn't include dependencies. Check [how-can-i-create-an-executable-jar-with-dependencies-using-maven](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) – user2953113 Sep 18 '15 at 17:56

2 Answers2

2

add -classpath flag in the command line ,pointing to the path where Webcam-Capture API exists in your file system, unless you want to create a single package executable.In your case It should be something like below

java  -classpath YOURJAR.jar;folder_of_dependant_jar/*;. com.awesome.pagackage.Starter

Where YOURJAR.jar contains the com.awesome.pagackage.Starter.main(String args[])

You also mentioned that your jar is a runnable jar it also means that while exporting/building you can do one of the following way.( NOTE , this feature is in eclipse , but you would get the idea ).Each of the following options you see in the library handling does specific things.

The first option: Extracts the dependent jar into your target jar as java packaging.This means if your package is com.awesome.package and the dependent jar has package logic.package; , after the runnable jar is build you could find both these package exists in your jar file.

The second option: I think it is more on eclipse specific since eclipse adds few classes of its own , of runnable generation, so I am not explaining it here.

The third option : is the most interesting one. it creates folder stucture like below

ndon_lib\external.jar ( external jar file ) ndon.jar ( your jar file )

This time the manifest.mf file contains something like below.

Class-Path: . ndon_lib/external.jar
Main-Class: com.awesome.pagackage.Starter

enter image description here

Abhiram mishra
  • 1,597
  • 2
  • 14
  • 34
1

You should set the classpath

java -cp "your.jar"  "yourclass"
Mike G
  • 4,232
  • 9
  • 40
  • 66