Today, it's going to take a day to study how to execute a Java program with a script, and finally realize, share
(1) Write an. sh file under Linux
(2) The contents of the document are as follows:
Copy Code code as follows:
#!/bin/sh//bash File Header
APP_HOME=/HOME/BLMCRM/CRM/A//The previous directory of the bin file in the Java file to execute, my directory is/HOME/BLMCRM/CRM/A/BIN/BLM ... (Do not write later), in short, is to write the bin directory in front of the section, because the jar package in the bin directory, if not in the bin, also so change the line
classpath= $APP _home/bin//bin Directory is of course a directory containing JAR packages.
For i in "$APP _home"/bin/*.jar//All jar packs are introduced here, the loops used here, of course, can also be written in this format one by one
Todo
Classpath= "$CLASSPATH": "$i"//environment variable in this format
Done
Export classpath=.: $CLASSPATH//Don't write this may say the main class is not found
echo ${classpath}//Print environment variable, can not write
java-xms50m-xmx250m Org.gdh.blm.exec.Syslog_csv
Exit (end)//execute Java program, where-xms50m-xmx250m is the setting for running memory, followed by the bin directory until the. class path, mine is Syslog_csv.class, so my last one is syslog_csv.
Do not know how to write detailed, everyone is not the same, for reference only, but the setting of the environment variable is the most important, I was the environment variable has been wrong, always according to the internet to find out, do not understand how, just have been wrong, in fact, the environment variable is the Java program you want to execute location, right,. The execution of SH is in the terminal input SH aa.sh