使用javac在一个包内编译四个java文件 [英] Compiling four java files within one package using javac

查看:402
本文介绍了使用javac在一个包内编译四个java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件夹中有四个java文件。他们都在同一个包。这是包声明

package 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 函数。)

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屋!

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