Because do not want to write Java-jar Jarfile, but want to write directly./jarfile can run the program.
#!/bin/bash- #===============================================================================# # File:shell_pack.SH# # USAGE:./shell_pack.SH# # DESCRIPTION: # # OPTIONS:---# REQUIREMENTS:---# BUGS:---# NOTES:---# AUTHOR:LWQ (28120), [email protected]# ORGANIZATION: # CREATED:Geneva/ A/ - Geneva: -: onPM cst# REVISION:---#===============================================================================#= = = FUNCTION ================================================================# name:usage# Description:display usage information.#===============================================================================functionusage () {Cat<<-EOT Usage: $0[Options]-P package-s script file1 file2 file3. Options:-h|Help Display This message-p|Package the output package name-j|jarfileThe jarfileEOT} #----------End offunctionUsage----------#-----------------------------------------------------------------------# Handle command line arguments#----------------------------------------------------------------------- whileGetopts": hp:j:"opt Do Case$optinchh|HELP) usage; Exit0 ;; P|package) package_name=$OPTARG;; J|jar) jar_file=$OPTARG;; \? )Echo-E"\ Option does not exist: $OPTARG \ n"The usage; exit1 ;; Esac#---End of Case--- DoneShift$ ($OPTIND-1))if[[-Z $package _name]]; Then Echo "package_name can ' t not be empty"Usage Exitfiif[[-Z $jar _file]]; Then Echo "Jar_file can ' t not be empty"Usage ExitfiGenerate_wrapper_script () {Local Wrapper_script=$1 Cat<<-'EOT'>$wrapper _script#!/bin/SHJava-jar $0 "[email protected]"if[$?-ne0]; Then Echo "Run Jar file failed."Exit1fiExit0#__SCRIPTEND__EOT}wrapfile=wrap_$$.SHEcho-E"start packing. \ n"Generate_wrapper_script $wrapfileCat$wrapfile $jar _file >$package _namechmod+x $package _nameEcho-E"\noutput: $package _name\n"RM-F $wrapfile
Save to Jar_wrapper.sh, using the method Example:
./jar_wrapper.sh-p/tmp/aaa-j/tmp/test_demo1.jar
Then, chmod +x/tmp/aaa &&/TMP/AAA will be able to run the program!
〖linux〗 Package a jar file into a Linux executable file