Compiling four java files within one package using javac
Solution 1
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
Solution 2
You can run by using command :- javac -cp src/com/**/*.java I am asuming there is no other dependenices and your root class name would be src only.
prometheuspk
Out of the night that covers me, Black as the pit from pole to pole, I thank whatever gods may be For my unconquerable soul. In the fell clutch of circumstance I have not winced nor cried aloud. Under the bludgeonings of chance My head is bloody, but unbowed. Beyond this place of wrath and tears Looms but the Horror of the shade, And yet the menace of the years Finds and shall find me unafraid. It matters not how strait the gate, How charged with punishments the scroll, I am the master of my fate: I am the captain of my soul. Invictus - William Ernest Henley
Updated on October 05, 2020Comments
-
prometheuspk over 3 years
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 usingjava
command in the CLI? here are the file names.
EnteringPoint.java
HidingProcess.java
ListFiles.java