在来自cmd的包中运行类 [英] Run class inside a package from cmd

查看:129
本文介绍了在来自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 the Hamzah.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屋!

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