Deploy to Linux and configure Java timer tasks

Source: Internet
Author: User

Java project deployment to Linux and configuring scheduled Tasks 53447391

1. Develop the program in Eclipse and compile it into a. class file

2, in Linux to create the corresponding directory, I created in Linux Statsharedataproject directory to store the program, while in this directory to create some of the following directories and files, where the Srcdata program to use the data, log log directory, lib The jar package used by the program to move the files needed to run the program to the corresponding directory
Write a picture description here
My program was sent in the Eclipse directory, so I created the Entity,main,utils directory under Linux.
Write a picture description here

3, the Linux directory can be created to upload the eclipse compiled. class file to the corresponding directory
eg
Write a picture description here

4. The next step is to write the start-stop script
Write a picture description here
The contents are as follows:

!/bin/sh

Source/etc/profile
Name=statsharedataproject
echo "--kill $NAME--"
Id=ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk ‘{print $2}‘
Echo $ID
For ID in $ID
Do
Kill-9 $id
echo "Kill $id"
Done
echo "—-!! —-"
Cd/root/yechunbo/project/statsharedataproject
Java_opts= "-server-xms256m-xmx1024m-xx:-usegcoverheadlimit-dappname=statsharedataproject- DJAVA.RMI.SERVER.HOSTNAME=127.0.0.1-DJAVA.NET.PREFERIPV4STACK=TRUE-XX:+USEPARALLELGC-XX:+USEPARALLELOLDGC-XX: Pa
Rallelgcthreads=8 "
Nohup Java-classpath.:./lib/commons-codec-1.6.jar:./lib/commons-logging.jar:./lib/dom4j-1.6.1.jar:./lib/ Commons-lang-2.4.jar:./lib/commons-logging-1.1.1.jar:./lib/fluent-hc-4.2.5.jar:./lib/httpclient-4.2.5.j
Ar:./lib/httpclient-cache-4.2.5.jar:./lib/httpcore-4.2.4.jar:./lib/httpmime-4.2.5.jar:./lib/json-20080701.jar: ./lib/jsoup-1.9.2.jar:./lib/json-lib-2.2.3-jdk15.jar:./lib/jxls-core-1.0.jar:./lib/statshare.jar:./
Lib/log4j-1.2.17.jar $JAVA _opts Main. Statbasicdata &
18
Note: $JAVA _opts Main. Statbasicdata This is the class that corresponds to start, here main. Statbasicdata:main corresponds to the directory, Statbasicdata corresponds to the class name under the directory, Statbasicdata. class has a corresponding main method;
here.:./lib/commons-codec-1.6.jar ... Is the jar package that the program needs to run

STOP.SP Script
Write a picture description here

The contents are as follows:

!/bin/sh

Name=statsharedataproject
echo "--kill $NAME--"
Id=ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk ‘{print $2}‘
Echo $ID
For ID in $ID
Do
Kill-9 $id
echo "Kill $id"
Done
echo "—-!! —-"
5. Write the start-stop script to run
Write a picture description here

You see that the program runs the output of the log, the program is deployed successfully.

6. Test stop.sh
Write a picture description here

7. Configure Scheduled Tasks
Write a picture description here

Observing the execution results of timed tasks

Attention:
When a scheduled task is configured, the timer task is executed but the program does not run, but the program runs correctly by running the program manually, and later it is found to be a problem with scripting. The script that was written previously was run by packaging the entire program into a jar package, and it was found that a script that did not perform this way in a timed task was swapped in the form above.
The nohup.out is not output when the program is executed by a timed task, and manual execution has the corresponding output in the nohup.out.

Deploy to Linux and configure Java timer tasks

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.