Sh script sharing for executing Java programs under Linux

  • 2020-04-01 03:31:20
  • OfStack

It took me about a day to figure out how to script a Java program

(1) write a.sh file under Linux

(2) the contents of the document are as follows:


#!/bin/sh         //Bash file header
APP_HOME=/home/blmcrm/crm/A      //To execute the Java file bin files in A directory, my directory is/home/BLMCRM/CRM/A/bin/BLM... (I won't write it later), but just write the part in front of the bin directory, because the jar is in the bin directory, if not in the bin, just change it to
CLASSPATH=$APP_HOME/bin           //The bin directory is, of course, the directory that contains the jars
for i in "$APP_HOME"/bin/*.jar    //Import all of the jars, the loop used here, and of course you can follow this format one by one & NBSP;;                                                                       Write < br / > do
 CLASSPATH="$CLASSPATH":"$i"       //Environment variables in this format
done
export CLASSPATH=.:$CLASSPATH        //If you don't write this, you might say you can't find the main class
echo ${CLASSPATH}                    //Print environment variables without writing
java -Xms50m -Xmx250m org.gdh.blm.exec.Syslog_csv
exit( The end of the )     //Execute the Java program, where -xms50m-xmx250m is the Settings for running memory and so on, followed by the path from the bin directory all the way to.class, my name is Syslog_csv. Class, so my last name is Syslog_csv. < br / >

Don't know what to write detailed is not detailed, each person is different, for reference only, but set the environment variable is one of the most important, I have been wrong, is the environment variable is always according to the Internet to come, don't know what happened, just always go wrong, actually environment variable is where you to perform a Java program, by the way, the execution of the sh is the terminal input sh aa. Sh


Related articles: