简体   繁体   中英

NoClassDefFoundError when runnable jar

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.

在此处输入图片说明

can anyone of you help me?

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

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

在此处输入图片说明

您应该设置类路径

java -cp "your.jar"  "yourclass"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM