Skip to content

Instantly share code, notes, and snippets.

@NcryptedWifKali
Forked from simonesestito/java.sh
Created October 5, 2018 23:13
Show Gist options
  • Select an option

  • Save NcryptedWifKali/c8baaf76559d0ed6cb9fd673b023e4d3 to your computer and use it in GitHub Desktop.

Select an option

Save NcryptedWifKali/c8baaf76559d0ed6cb9fd673b023e4d3 to your computer and use it in GitHub Desktop.
Termux script to run Java programs
#!/data/data/com.termux/files/usr/bin/bash
#
# Suggested usage:
# copy this file in your home folder,
# rename it .java.sh (hidden file),
# make this file executable,
# create an alias java=~/.java.sh in .bashrc.
# Now you can call it everywhere typing
# java File1.java File2.java
#
# NOTE: the first Java class in arguments must be the Main class
# e.g.: java App.java Component.java
# In this case, App must be the main public class because it's the first argument
#
status(){
echo -e "\033[1;32m// $*...\033[0m"
}
stop(){
echo -e "\033[1;37;41m(!) $*\033[0m"
clean
exit 1
}
clean(){
status Closing
rm -rf *.dex *.class oat/
}
status Checking files
if [ $# -eq 0 ]; then
stop Usage: java FILES
fi
for f in $*; {
if [ ! -f $f ]; then
stop File $f is missing
fi
}
status Compiling
ecj $* || stop Compilation error
status Processing file names
cls=''
for file in $*; {
j=`echo $file | cut -f 1 -d '.'`
cls="$cls $j.class"
}
status Building dex file
dx --dex --output out.dex $cls || \
stop Error building dex file for DalvikVM
status Starting
main=`echo $1 | cut -f 1 -d '.'`
dalvikvm -cp out.dex $main
clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment