How to compile a Java application in Unix?

To compile a Java application in Linux, consider the following shell script.

compile.sh

#!/bin/sh

DIR_LIB=$1

for file in `ls $DIR_LIB/*.jar`
do
   CLASSPATH=$file:$CLASSPATH
done

export CLASSPATH

javac -d classes $2/*.java

You need to provide three parameters to run the above file.
1. Library path where *.jar files used by the application are present.
2. Path where the Java source files are present
3. Path where the Java Class files are to be generated.

Note: Please provide absolute or full path for all the above parameters.

$ ./compile.sh <LIB_PATH> <SRC_PATH> <CLASSES_FOLDER_PATH>

Search