在来自cmd的包中运行类 [英] Run class inside a package from cmd
问题描述
你好
我在一个名为 hamzah 的程序包中有一个名为 Hamzah 的类,我尝试从命令行运行它,但始终有 NoClassDefFoundError 该类正确编译,并且.class文件已生成,但没有运行
我尝试执行以下操作:
Hello
i have a class called Hamzah inside a package called hamzah i tried to run it from Command line but always i have NoClassDefFoundError the class compiled correctly and .class file produced but it didn''t run
i try to do the following :
<br />
<C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>javac Hamzah.java>
编译成功
这是要运行的:
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>java -cp . Hamzah
在这里出错.
Compiled successfully
and this for run :
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>java -cp . Hamzah
Error here .
推荐答案
如果与Hamzah.class
文件位于同一文件夹中,则可以使用以下命令直接调用它:
If you''r in the same folder as theHamzah.class
file, you can invoke it directly using:
java Hamzah
假定Hamzah
具有有效的main
方法.
假设您的课程在软件包com.hamzah
中,请从src
目录构建并运行:
This assumes Hamzah
has a valid main
method.
Assuming your class is in package com.hamzah
, build and run from the src
directory:
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src>javac com\hamzah\Hamzah.java
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src>java com.hamzah.Hamzah
尝试从上面的目录进行调用,如下所示:
Try from the directory above and call it like:
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com>java hamzah.Hamzah
// or
java hamzah/Hamzah
这篇关于在来自cmd的包中运行类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!