[英]NoClassDefFoundError when runnable jar
Hi Guys I have included the Webcam-Capture API in my project. 嗨,大家好,我在项目中加入了Webcam-Capture API。
When I run it in Netbeans everything works fine. 当我在Netbeans中运行它时,一切正常。 But when i compile everything to a runnable jar i get this message trying to run it by cmd line.
但是,当我将所有内容编译到可运行的jar时,我收到此消息,尝试通过cmd行运行它。
can anyone of you help me? 你们中有人可以帮助我吗?
i already tried to unbound and rebound all jars and changing jdks but its not working 我已经尝试解除绑定并反弹所有罐子并更改jdks,但是它不起作用
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 在命令行中添加-classpath标志,指向文件系统中Webcam-Capture API所在的路径,除非您要创建单个程序包可执行文件。在这种情况下,它应该类似于以下内容
java -classpath YOURJAR.jar;folder_of_dependant_jar/*;. com.awesome.pagackage.Starter
Where YOURJAR.jar contains the com.awesome.pagackage.Starter.main(String args[]) 其中YOURJAR.jar包含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. 您还提到您的jar是可运行的jar,这也意味着在导出/构建时可以执行以下一种方法。(注意,此功能在eclipse中,但是您会明白的)。请参见库处理中的特定操作。
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; 第一种选择:将依赖的jar提取为java打包到目标jar中。这意味着您的包是com.awesome.package,并且依赖的jar具有包逻辑。 , after the runnable jar is build you could find both these package exists in your jar file.
,在构建可运行的jar之后,您会发现这两个软件包都存在于jar文件中。
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. 第二种选择:我认为它更多地是针对eclipse的,因为eclipse自己添加了一些可运行的类,因此在这里我不做解释。
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 ) ndon_lib \\ external.jar(外部jar文件)ndon.jar(您的jar文件)
This time the manifest.mf file contains something like below. 这次manifest.mf文件包含如下内容。
Class-Path: . ndon_lib/external.jar
Main-Class: com.awesome.pagackage.Starter
您应该设置类路径
java -cp "your.jar" "yourclass"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.