I spent almost a day today researching how to use scripts to execute java programs. I finally realized it. Let me share it.
(1) Write a .sh file under linux
(2) The content of the file is as follows:
Copy the 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 be executed. My directory is /home/blmcrm/crm/A/bin/blm...(not included in the following) (written), in short, write the part in front of the bin directory, because the jar package is in the bin directory. If it is not in the bin, just change it in the same way.
CLASSPATH=$APP_HOME/bin //The bin directory is of course the directory containing the jar package.
for i in "$APP_HOME"/bin/*.jar //Introduce all jar packages, the loop used here, of course, you can also write them one by one according to this format
do
CLASSPATH="$CLASSPATH":"$i" //Environment variables are in this format
done
export CLASSPATH=.:$CLASSPATH //If you don’t write this, it may say that the main class cannot be found.
echo ${CLASSPATH} //Print environment variables, you don’t need to write them
java -Xms50m -Xmx250m org.gdh.blm.exec.Syslog_csv
exit (end) //Execute the java program, where -Xms50m -Xmx250m is the running memory settings, and the following is the path from the bin directory to .class. Mine is Syslog_csv.class, so my last one is Syslog_csv.
I don’t know if it’s detailed or not. Everyone’s situation is different. It’s just for reference. However, environment variables are the most important thing when setting. My environment variables are always wrong. I always follow what I can find online. I don’t understand what’s going on. , I keep getting errors. In fact, the environment variable is the location of the java program you want to execute. By the way, to execute .sh, enter sh aa.sh in the terminal.