本文介绍了在来自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 .

推荐答案

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


C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com>java hamzah.Hamzah
// or
java hamzah/Hamzah


这篇关于在来自cmd的包中运行类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 03:22