〖linux〗 Package a jar file into a Linux executable file

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.