Launch shell script for Java application

Source: Internet
Author: User

For Java Applications (non-Web applications), after deployment, a startup script is often required to load some Third-party jar packs and start the application.

For Java applications, I generally prefer to write the directory structure of a program as follows:

myapp
     |----lib
     |----bin
             |----packages
               一些配置文件和属性文件
               一个startup.sh、或bat启动脚本

Where packages is the root package of the program. These include child packages and class files.

In the package, there is a MAIN.CALSS class, which serves as the entry point for the program.

Here is a general formulation:

startup.sh

#!/bin/sh
programdir="."
num=$#
temp=$CLASSPATH
#setting libs path
libs=../lib/*
append(){
                 temp=$temp":"$1
}
for file in $libs;    do
                 append $file
done
export CLASSPATH=$temp:.:../:$programdir
export LANG=zh_CN
nohup java -classpath $CLASSPATH    packaages.xxx.yyy.Main &

So, as long as the program is organized in the way above, the startup script needs to change the package path in front of main.

Nohup: There is a nohup before the last line in the previous script, which attaches the input and output of the program to the Nohup.out file in the current directory.

is to run the program as a background process and not shut down because the terminal is closed.

Source: http://lavasoft.blog.51cto.com/62575/204713

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.