The use case is simple. I got the source files that were created using Eclipse. So, there is a deep directory structure, where any Java class could be referring to another Java class in the same, child, sibling or parent folder.
How do I compile this whole thing from the terminal using javac ?
You'd have to use something like Ant to do this hierarchically:
http://ant.apache.org/manual/Tasks/javac.html
You'll need to create a build script with a target called compile containing the following:
Then you''ll be able to compile all files by running:
Alternatively, import your project into Eclipse and it will automatically compile all the source files for that project.
Windows solution: Assuming all files contained in sub-directory 'src', and you want to compile them to 'bin'.
If src contains a .java file immediately below it then this is faster
With Bash 4, you can just enable globstar
and then do
There is a way to do this without using a pipe character, which is convenient if you are forking a process from another programming language to do this:
Though if you are in Bash and/or don't mind using a pipe, then you can do:
Following is the method I found:
1) Make a list of files with relative paths in a file (say FilesList.txt) as follows (either space separated or line separated):
2) Use the command:
This will compile all the files and put the class files inside classes directory.
Now easy way to create FilesList.txt is this: Go to your source root directory.
But, this will populate absolute path. Using a text editor "Replace All" the path up to source directory (include \ in the end) with "" (i.e. empty string) and Save.
If all you want to do is run your main class (without compiling the
.java
files on which the main class doesn't depend), then you can do the following:or
javac
would automatically resolve all the dependencies and compile all the dependencies as well.