Java Compile – Command Line

Why Compile?

  • .java files are converted into .class files which are bytecodes
  • This compilation is done by using javac command which stands for java-compiler
  • These bytecodes can be executed by JVM at runtime.

How to compile bunch of .java files together :

  • First create a file with the names of all .java files using below command
find . -type f -iname "*.java" > source.txt
  • Then compile it using javac command
javac @source.txt
  • You can provide the jar in the class path using -cp attribute
javac -cp "lib/*" @source.txt
  • Verbose output can be triggered using -verbose attribute
javac -verbose -cp "lib/*" @source.txt
  • You can put all the .class files into bin directory using -d attribute
javac -verbose -cp "lib/*" -d bin @source.txt

Leave a Comment