document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #! /usr/bin/env bash
  2.  
  3. build_dir=\'build\'
  4. lib_dir=\'lib\'
  5. dist_dir=\'dist\'
  6.  
  7. ###
  8. ### Okay, say that you have a normal Java project directory tree
  9. ### structure that looks like this:
  10. ###
  11. ###    $ ls
  12. ###    build lib   src
  13. ###
  14. ### In your src directory you have some Java source files that
  15. ### are arranged in packages.
  16. ###
  17. ###    src/com/something/app/ProgramMain.java
  18. ###    src/com/something/app/utils/Support.java
  19. ###
  20. ### When those files get compiled into class files, the Java
  21. ### class files typically are placed in the build directory.
  22. ###
  23. ###    build/com/something/app/ProgramMain.class
  24. ###    build/com/something/app/utils/Support.class
  25. ###
  26. ### To execute your Main class from the command line you must
  27. ### include a lot of information for the class path such as  
  28. ### the exact location of any external libraries, and every
  29. ### compiled class that your program needs to run.  This can
  30. ### get very complicated.
  31. ###
  32. ### This script will simplify the execution of your compiled
  33. ### Java program.  Just name this script after the main class of
  34. ### your program, and the script will do the rest for you.
  35. ###
  36. ### For example, if your program is called "ProgramMain", you
  37. ### should name this script that, or "programmain".  Case does
  38. ### not matter.
  39. ###
  40. ### Make this script executable,
  41. ###
  42. ###    $chmod +x ./programmain
  43. ###
  44. ### And run it like a regular linux program.
  45. ###
  46. ###    $./programmain
  47. ###
  48.  
  49. if [ -h $0 ]; then
  50.   link=$(readlink $0)
  51.   me=$(basename $link)
  52.   path_of_this_script=`dirname $link`
  53. else
  54.   me=$(basename $0)
  55.   path_of_this_script=`dirname $0`
  56. fi
  57. path_of_this_script=${path_of_this_script/".\\/"/"$(pwd)\\/"}
  58.  
  59. java=$(which java)
  60.  
  61. [ -z $java ] && { echo "You have not installed Java"; exit 1; }
  62.  
  63. build_dir=$path_of_this_script/$build_dir
  64. lib_dir=$path_of_this_script/$lib_dir
  65. dist_dir=$path_of_this_script/$dist_dir
  66.  
  67. main_class=$(find $build_dir | grep -i $me)
  68. main_class=${main_class:${#build_dir}+1}
  69. main_class=${main_class/%.class/\'\'}
  70. main_class=${main_class//\\//\'.\'}
  71.  
  72. lib=$(find $lib_dir)
  73. for file in $lib; do class_path=$class_path$file:; done
  74.  
  75. build=$(find $build_dir)
  76. for dir in $build; do [ -d $dir ] && class_path=$class_path$dir:; done
  77.  
  78. if [ -f $dist_dir/$me*.jar ]; then
  79.   $java -jar $dist_dir/$me*.jar $@
  80. else
  81.   $java -cp $class_path $main_class $@
  82. fi
');