Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

command line - Compiling four java files within one package using javac

I have four java files in my folder. They are all in the same package. Here's the package declaration
package com.osama.GHide

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the project's root directory:

javac src/com/osama/GHide/*.java

To run, assuming no other dependencies:

java -cp ./src com.osama.GHide.EnteringPoint

(Assuming EnteringPoint has the normal main function.)

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.

To put them in a different directory, use the -d option and supply a path.

javac -d bin src/com/osama/GHide/*.java

Then to run:

java -cp ./bin com.osama.GHide.EnteringPoint

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...