Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile multiple java source files in command line

Tags:

java

build

javac

I know running javac file1.java produces file1.class if file1.java is the only source file, then I can just say java file1 to run it.

However, if I have 2 source files, file1.java and file2.java, then how do I build the program?

like image 555
Alfred Zhong Avatar asked Jan 26 '11 01:01

Alfred Zhong


People also ask

How do I compile all Java files at once?

Using Argument Files When there are multiple packages to compile, then using the javac command with an argument file comes in handy. An argument file can include both the javac options and source file names.

Which command is used to compile a Java source file?

Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.


2 Answers

Try the following:

javac file1.java file2.java 
like image 124
ryanprayogo Avatar answered Oct 12 '22 08:10

ryanprayogo


or you can use the following to compile the all java source files in current directory..

javac *.java 
like image 28
ajduke Avatar answered Oct 12 '22 08:10

ajduke