Java JAR - 线程“main”中的异常java.lang.NoClassDefFoundError [英] Java JAR - Exception in thread "main" java.lang.NoClassDefFoundError

查看:151
本文介绍了Java JAR - 线程“main”中的异常java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 上工作。我制作了简单的GUI应用程序,使用3个类。 Main是Test.class,包含main方法。我已经从控制台级别将它们全部打包到JAR中。现在我有kalkulator.jar,其中包含:Test.class,MyFrame.class,MyPanel.class和META-INF文件夹。在META_INf中有MANIFEST.MF。 MANIFEST.MF中的内容是:Main-Class:Test和换行符。现在我尝试使用以下命令从控制台打开我的JAR:
java -jar kalkulator.jar
我得到:线程中的异常mainjava.lang.NoClassDefFoundError:Test(错误名称:myproject / Test )
myproject是我所有课程的包。
那我怎么解决呢?

Im working on Ubuntu. I made simple GUI app which uses 3 classes. Main is Test.class which contains main method. I have packed them all into JAR from console level. Now I have "kalkulator.jar" which contains: Test.class, MyFrame.class, MyPanel.class and META-INF folder. In META_INf there is MANIFEST.MF. What is in MANIFEST.MF is: "Main-Class: Test" and newline character. Now I try to open my JAR from console using: java -jar kalkulator.jar I get: "Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: myproject/Test") myproject is package of all my classes. So how can I solve it?

推荐答案

你需要做以下事情:


  1. 确保jar中的目录层次结构绝对与包层次结构相匹配。这些类必须位于jar中名为myproject的目录中。如果它们只是顶级,则无效。

  1. make sure that the directory hierarchy in your jar matches the package hierarchy, absolutely. The classes have to be in a directory named 'myproject' in the jar. If they are just at top level, it won't work.

使用main方法将Main-Class名称设为类的完全限定名称。 (即myproject.Test)。

Make the Main-Class name the fully qualified name of the class with the main method. (i.e. myproject.Test).

学习使用构建工具,例如蚂蚁,做这一切。

Learn to use a build tool, e.g. ant, to do all this.

这篇关于Java JAR - 线程“main”中的异常java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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