从命令行Linux运行Java程序 [英] Running Java Program from Command Line Linux
问题描述
我不是很有经验的java和这是驱动我疯了。我写了一个java程序 FileManagement
,我需要从命令行运行它。
I am not very experience with java and this is driving me crazy. I wrote a java program FileManagement
and I need to run it from the command line.
命令行与 javac FileManagement / *。java
将创建该文件夹中的所有类,但当我尝试 java FileManagement.Main
它说:
I can compile it from the command line with javac FileManagement/*.java
which will create all the classes in that folder but when I try java FileManagement.Main
it says :
线程main中的异常java.lang.NoClassDefFoundError:
FileManagement / Main
Exception in thread "main" java.lang.NoClassDefFoundError: FileManagement/Main
事情是,我在远程计算机上尝试过同样的过程,它工作正常。
The thing is that I have tried this same procedure in a remote computer and it is working fine. It is not working on mine.
推荐答案
如果你的 Main
在 FileManagement
包中,然后尝试:
If your Main
class is in a package called FileManagement
, then try:
java -cp . FileManagement.Main
在 FileManagement
文件夹。
如果您的 Main
类不在包中(默认包),则 cd 到 FileManagement
文件夹,然后尝试:
If your Main
class is not in a package (the default package) then cd to the FileManagement
folder and try:
java -cp . Main
有关CLASSPATH的更多信息以及JRE如何查找类:
More info about the CLASSPATH and how the JRE find classes:
- How Classes are Found
- Setting the class path (Solaris/Linux)
- http://en.wikipedia.org/wiki/Classpath_(Java)
这篇关于从命令行Linux运行Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!