使用 javac 在一个包中编译四个 java 文件 [英] Compiling four java files within one package using javac
问题描述
我的文件夹中有四个 java 文件.它们都在同一个包中.这是包声明包com.osama.GHide
I have four java files in my folder. They are all in the same package. Here's the package declaration
package com.osama.GHide
所有这些类都在同一个包中.我想知道如何使用 javac
编译它们(我的意思是我不知道如何编译多个相互使用的文件).一旦完成,我如何在 CLI 中使用 java
命令启动?这是文件名.EnteringPoint.java
HidingProcess.java
ListFiles.java
All of these classes are in the same package. I want to know how can I compile them using javac
(i mean i do not know how to compile multiple files that are using each other). And once that is done how do I launch then using java
command in the CLI? here are the file names.
EnteringPoint.java
HidingProcess.java
ListFiles.java
推荐答案
从项目的根目录:
javac src/com/osama/GHide/*.java
运行,假设没有其他依赖:
To run, assuming no other dependencies:
java -cp ./src com.osama.GHide.EnteringPoint
(假设 EnteringPoint
具有正常的 main
功能.)
(Assuming EnteringPoint
has the normal main
function.)
javac
命令编译包目录中的所有 .java
文件.因为它们都在同一个包/目录中,所以这是有效的.它还会将生成的 .class
文件放在同一目录中,这可能是您想要的,也可能不是.
The javac
command compiles all the .java
files in the package's directory. Since they're all in the same package/directory, this works. It also puts the generated .class
files in the same directory, which may or may not be what you want.
要将它们放在不同的目录中,请使用 -d
选项并提供路径.
To put them in a different directory, use the -d
option and supply a path.
javac -d bin src/com/osama/GHide/*.java
然后运行:
java -cp ./bin com.osama.GHide.EnteringPoint
这篇关于使用 javac 在一个包中编译四个 java 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!