尝试在命令提示符下运行.jar文件 [英] trying to run a .jar file in command prompt

查看:128
本文介绍了尝试在命令提示符下运行.jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用命令提示符(Windows XP)运行jar文件但是获取NoClassDefFoundError。

I am trying to run a jar file using my command prompt (Windows XP) but get NoClassDefFoundError.

我的DateAndTime.class文件位于名为dateandtime的文件夹中并且还在源文件中指出了一个名为dateandtime的包。

I have my DateAndTime.class file in a folder called dateandtime and also indicated a package called dateandtime in the source file.

在文件夹外我有一个带有规范的manifest.mf文件

Outside the folder I have a manifest.mf file with specification


Main-Class:dateandtime.DateAndTime

Main-Class: dateandtime.DateAndTime

我把它放在命令文件中


jar cmf manifest.mf myJarFile.jar dateandtime

jar cmf manifest.mf myJarFile.jar dateandtime

这会在manifest.mf所在的文件夹中创建myJarFile.jar。

and this creates the myJarFile.jar in the same folder as manifest.mf.

当我尝试运行这个jar文件时,我得到了NoClassDefFoundError

When I try to run this jar file however I get the NoClassDefFoundError


java -jar myJarFile.jar

java -jar myJarFile.jar

如果我jave在没有指定包的同一目录中的所有类,然后.jar文件运行正常,但是一旦我尝试指定包,e虽然创建了myJarFile.jar但我得到了错误。

If I jave all the classes in the same directory with no package specified then the .jar file runs fine but as soon as I try to specify a package, even though myJarFile.jar was created I get the error.

为什么会这样?

问候

推荐答案

如果您收到 NoClassDefFoundError ,则表示编译期间出现的类您的课程在执行期间缺席。这意味着您的JAR文件不包含您的类所需的所有依赖项以便运行。由于您的问题缺乏项目结构的详细信息,我只建议您重新访问应用程序的依赖关系树,并确定 所有 需要包含在JAR中的类。

If you are getting a NoClassDefFoundError it means a class that was present during compilation of your classes is absent during their execution. Which implies that you JAR file does not contain all the dependencies requires by your classes in order to run. Since your question is lacking detail on your project structure I can only recommend you revisit your application's dependency tree and determine all the classes that need to be included in the JAR.

这篇关于尝试在命令提示符下运行.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆