简体   繁体   English

用包执行类文件?

[英]execute class files with packages?

In general, how can one execute a .class file through powershell/command prompt that contains packages in it? 一般来说,如何通过包含其中包的powershell /命令提示符来执行.class文件? I'm still having trouble with that. 我仍然遇到麻烦。 Assume the file is ClassFile.class , with the package called Pack and the class file's location in C:\\Program Files\\Folderhere\\ClassFile.class . 假设文件是ClassFile.class ,包名为Pack ,类文件位于C:\\Program Files\\Folderhere\\ClassFile.class

If the class is in a package called Pack then you'd do 如果该类位于名为Pack那么您可以这样做

java Pack.ClassFile

Have you copied the compiled code around at all, moving it from one directory to another? 您是否复制了编译后的代码,将其从一个目录移动到另一个目录? If you have, it's important to maintain the directory structure that it was originally compiled into. 如果有,那么保持最初编译的目录结构很重要。

If I was writing some code in a package and compiling and running it, these are the steps I'd take. 如果我在包中编写一些代码并编译并运行它,这些是我要采取的步骤。 Assume we've cd'd to a clean directory first. 假设我们首先cd到一个干净的目录。

mkdir Pack
vi Pack/ClassFile.java
javac Pack/ClassFile.java
java Pack.ClassFile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM