execute a .jar in weblogic application server

0

Good friends, I am developing an application that is going to run every so often, at first I think that as an application, the method is executed at the indicated time with the annotation @Schedule(minute = "*/3", hour = "*", persistent = false) , but well, as now it is not going to need a view as such, and not to be displaying a file .WAR , I thought to create it as a .JAR, now create the .JAR and the method that would run with main but I have no idea how make a .JAR displayed in a weblogic application server run every so often, so I read that with a cron job or crons but I really do not know much about it, I hope you can suggest some other idea or method, thanks

    
asked by Jdeveloper 11.07.2017 в 19:34
source

1 answer

0

I leave a way of how I send to call a job that is basically a javaApplication (.jar), for it is done using crontab and a shell that commands to run the jar.

What is Crontab?

Crontab is a simple text file that stores a list of commands to be executed at a time specified by the user. Crontab will verify the date and time the script or command should be executed, the execution permissions and it will be executed in the background. Each user can have their own crontab file, in fact the / etc / crontab is assumed to be the crontab file of the root user, when normal users (and even root) want to generate their own crontab file, then we will use the crontab command.

Crontab is the easiest way to manage cron tasks on multi-user systems, either as a simple system user or root user.

Creating the shell that will call the jar:

#!/bin/bash

#ejecuta una llamada a un jar el cual edita los archivos rechazados por intelar, modifica fecha y secuencial
# una vez editados son enviados a intelar

rootWFL=$( cd 'dirname $0' >/dev/null; pwd );

        EXITCODE=;                                   
                #funcion que ejecuta el jar
                RunJava 
                EXITCODE=$?;                                        

                DISPLAY "El exit code ::--->  $EXITCODE";

              if [ "$EXITCODE" != "0" ]
                then
                    DISPLAY "System exit es diferente de 0 , finalizo con error -1  "
                else            
                    DISPLAY "Ejecución correcta de jar  ::---> ";
                    D
                fi          

# FUNCION PARA EJECUTAR JAVA 
function RunJava
{
echo "Mandando llamar jar con ruta "
    #ejecuta java, puedes indicar la ruta donde está o pasarla por variable
    java $DEBUG -jar $rootDir/mijarJob.jar ;
}   

How to add tasks to crontab?

We execute the edition of the crontab with crontab -e , in some distros (like ubuntu) it gives us the option of choosing the editor of texts that we want, the others we are left with vi. The crontab file will look something like this.

  

m h sun mon dow user command

where :

  • m corresponds to the minute the script is to be executed, the value goes from 0 to 59
  • h the exact time, the 24 hour format is handled, the values go from 0 to 23, being 0 at 12:00 midnight.
  • Sun refers to the day of the month, for example you can specify 15 if you want to run every day 15
  • dow means the day of the week, it can be numeric (0 to 7, where 0 and 7 are Sunday) or the first 3 letters of the day in English: mon, tue, wed, thu, fri, sat, sun.
  • user defines the user that will execute the command, can be root, or another different user as long as you have execution permissions of the script.
  • command refers to the command or absolute path of the script to run, example: /home/user/scripts/update.sh, if at all call a script this should be executable

Example of tasks with crontab

  

15 10 * * * user /home/user/scripts/RunJava.sh

It will run the update.sh script at 10:15 a.m. every day

  

15 22 * * * user /home/user/scripts/RunJava.sh

It will run the update.sh script at 10:15 p.m. every day

00 10 * * 0 root apt-get -y update Root user It will run an update every Sunday at 10:00 a.m

  

45 10 * * sun root apt-get-and update

Root user will run an update every Sunday (sun) at 10:45 a.m

  

30 7 20 11 * user /home/user/scripts/RunJava.sh

On November 20 at 7:30 the user will run the script

  

30 7 11 11 sun user /home/usuario/scripts/pastel_con_velitas.sh

On November 11 at 7:30 a.m. and that it is Sunday, the user will celebrate

  

01 * * * * user /home/user/scripts/molestorecordatorio.sh

An annoying reminder every minute of every hour every day (NOT recommended).

The same can be handled with special ranges:

  

30 17 * * 1,2,3,4,5

At 5:30 in the afternoon every day from Monday to Friday.

  

00 12 1,15,28 * *

At 12 every day, first, fifteenth and 28th of each month (ideal for payroll)

If this is confusing, crontab handles special strings to define these ranges.

  • @reboot Run once, at the start
  • @yearly runs only once a year: 0 0 1 1 *
  • @annually same as @yearly
  • @monthly runs once a month, the first day: 0 0 1 * *
  • @weekly Weekly the first minute of the first hour of the week. 0 0 * 0 ".
  • @daily daily, at 12:00 A.M. 0 0 * * *
  • @midnight same as @daily
  • @hourly at the first minute of each hour: 0 * * * *

Example of my crontab:

# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m   h  dom mon dow   command
  0   8   *   *  1-7    /home/usuario/scripts/RunJava.sh >> /home/usuario/scripts/logCron/runjava.cron.log 2>&1

Likewise you could look for other forms using other tools such as Quartz

    
answered by 11.07.2017 / 20:31
source