如何从命令行在Windows上运行.class文件? [英] How do I run .class files on windows from command line?
问题描述
我正在尝试从命令行运行.class文件。它在我手动移动到它存储的目录时有效,但是当我尝试这样的事情时:
I'm trying to run .class file from command line. It works when I manually move to the directory it's stored in, but when I try something like this:
java C:\Peter\Michael\Lazarus\Main
它说无法找到主类。除了制作.jar文件之外,还有其他解决办法吗(我知道.jar是最好的解决方案,但此时此刻不是我要找的那个)?
it says it can't find the main class. Is there any solution to this other than making a .jar file (I know that .jar is the best solution, but at this moment isn't the one I'm looking for)?
推荐答案
Java应用程序启动器(又名 java.exe
或简称 java
)需要类名作为其参数,因此您无法传递文件名(特别是不包含目录的文件名。
The Java application launcher (a.k.a java.exe
or simply java
) expects a class name as its argument, so you can't pass it a file name (especially not one that includes a directory.
您可以告诉它在哪里使用 -classpath
选项(或其简短形式 -cp
)查找该类但是:
You can tell it where to look for that class by using the -classpath
option (or its short form -cp
) however:
java -classpath C:\Peter\Michael\Lazarus\ Main
这篇关于如何从命令行在Windows上运行.class文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!