2

I understand the command would be javac file_name.java but how would I put together a shell script which could compile several java files?

I was also thinking about copying the files, which I presume I just use cp and absolute file path referencing.

4

2 に答える 2

1

Create a .sh file and add the following contents. Make the file as executable and run it. (Specify the complete path along with the file name)

#! /bin/sh
javac sample.java
于 2012-08-18T21:17:30.450 に答える
0

このスクリプトを試してください:compile_java_files.sh

#!/bin/sh

typeset -r JAVA_FILES_DIR=$(cd full_path_to_java_files 2>/dev/null ; pwd)   # JAVA FILES DIRECTORY

LOG_DIR="/tmp/java_compilation/logs"    # Create this dir or use another one

for java_file in `ls $JAVA_FILES_DIR`;
do
    javac $java_file
    return_status=`echo $?`
    if [ $return_status -ne 0 ]
    then
        echo "Failed to compile $java_file" >> $LOG_DIR/$java_file.ERR

        exit 1
    fi
done

次に、スクリプトを実行します(Javaファイルを含むディレクトリへのパスを指定することを忘れないでください)。

chmod +x compile_java_files.sh
./compile_java_files.sh
于 2012-08-18T23:50:42.837 に答える