-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgedit_java_compile_and_run
38 lines (32 loc) · 1.44 KB
/
gedit_java_compile_and_run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
FILE_ROOT_PATH=$GEDIT_CURRENT_DOCUMENT_PATH
FILE_NAME=$GEDIT_CURRENT_DOCUMENT_NAME # file name
PROJECT_DIR=${GEDIT_CURRENT_DOCUMENT_PATH%/src/*} # project directory, src directory must be located under this
BIN_PATH=$PROJECT_DIR/bin # binary files directory(.class files)
SRC_PATH=$PROJECT_DIR/src # source files directory(.java files)
PACKAGE_PATH=${GEDIT_CURRENT_DOCUMENT_PATH#*/src/} # Path to the file under src file, e.g com/example/Test.java
QUALIFIED_CLASS_NAME=${PACKAGE_PATH//\//\.}
QUALIFIED_CLASS_NAME=${QUALIFIED_CLASS_NAME%*\.java}
printf "################################ PROJECT INFO ###################################\n"
printf "File name : %s\n" "$FILE_NAME"
printf "File root path : %s\n" "$FILE_ROOT_PATH"
printf "Qualified class name : %s\n" "$QUALIFIED_CLASS_NAME"
printf "Package path : %s\n" "$PACKAGE_PATH"
printf "Binary files directory : %s\n" "$BIN_PATH"
printf "Source files directory : %s\n" "$SRC_PATH"
printf "##################################################################################\n"
if ! [ -d $BIN_PATH ]
then
mkdir $BIN_PATH
fi
if [ $JAVA_HOME == "" ]
then
echo "You need to install JDK."
else
javac -classpath $SRC_PATH -d $BIN_PATH $FILE_ROOT_PATH
fi
if [ $? -eq 0 ]
then
printf "\n\n"
java -classpath $BIN_PATH $QUALIFIED_CLASS_NAME
fi